Yours sincerely,<br />yuyong<br /> <br /> <br /> E-mail:yuyong22@hotmail.com<br /> msn: yuyong22@hotmail.com<br /> Skype:yuyong88
Originally posted by yu yong:
Sir, your question is the answer.
"Unreachable statement" citing line 1
'test()' method will throws Error all the time, so System.out.println("test"); is "Unreachable statement"
that is why you got a compilation error.
My question is why are we not getting a compilation error saying "Unreachable statement" citing line 1?
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
The rationale for this differing treatment is to allow programmers to define "flag variables" such as:
static final boolean DEBUG = false;
and then write code such as:
if (DEBUG) { x=3; }
The idea is that it should be possible to change the value of DEBUG from false to true or from true to false and then compile the code correctly with no other changes to the program text.
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
[Anand]: Even if it doesn't, IMHO, it only reflects a QoI issue, not a language issue.
Actually, details of reachability analysis are specified in the Java Language Specification. Whenever you get an "unreachable code" error, it's because the compiler was required to give you one. And when you don't get one, as in this case, it's because the compiler is forbidden to do so.
That's generally true for all compiler errors - Java's creators wanted to avoid the situations of having code that compiles and works on one machine but not another. Of course this doesn't always work out perfectly, but that's the intent.
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Regards,
Rohit.
SCJP 5.0<br /> <br />"Skills are started with learning and mastered with improvement. Nothing is hereditary except death" BUDDHA...
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Originally posted by Hasitha Randika:
look at the code carefully if you are not using brackets the immediate statement take as the if and the next one as the else
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery