Why Java identifies unreachable code only in case of while loop? -
this question has answer here:
if have code like
public static void main(string args[]){ int x = 0; while (false) { x=3; } //will not compile }
compiler complaint x=3
unreachable code if have code like
public static void main(string args[]){ int x = 0; if (false) { x=3; } for( int = 0; i< 0; i++) x = 3; }
then compiles correctly though code inside if statement
, for loop
unreachable. why redundancy not detected java workflow logic ? usecase?
as described in java language specification, feature reserved "conditional compilation".
an example, described in jls, may have constant
static final boolean debug = false;
and code uses constant
if (debug) { x=3; }
the idea provide possibility change debug
true
false
without making other changes code, not possible if above code gave compilation error.
Comments
Post a Comment