Page 1 of 1

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

Posted: Fri Nov 28, 2014 1:30 am
by gparLondon
Why is not compiler complains about unreachable code here?

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

Posted: Fri Nov 28, 2014 1:50 am
by admin
The compiler specifically makes an exception for an if statement.

final static boolean DEBUG = false;
if(DEBUG){
//ideally, this block is unreachable but the compiler allows it.
}

The reason is explained here: http://docs.oracle.com/javase/specs/jls ... #jls-14.21 (at the end)

HTH,
Paul.