Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1065 :

Posted: Sun Oct 19, 2014 3:58 pm
by DAlley
I would have thought that since the code that prints "4" would be unreachable, this would cause the code to not compile. I guess the compiler is not able to figure that out because the value of flag is not known until run time?

Re: About Question enthuware.ocajp.i.v7.2.1065 :

Posted: Sun Oct 19, 2014 7:46 pm
by admin
That is correct. flag is a variable and so its value is not known to the compiler. But even if it were a constant, the code would compile because JLS permits an unreachable if block to support conditional compilation. Please see Section 14.21 (towards the end) for details.

HTH,
Paul.