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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
gparLondon
Posts: 63
Joined: Fri Oct 31, 2014 6:31 pm
Contact:

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

Post by gparLondon »

Why is not compiler complains about unreachable code here?

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 201 guests