wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes If doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "If doubt" Watch "If doubt" New topic
Author

If doubt

sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
Read from JLS the following quote...
--------------------------------------------------
14.7 Statements are thus gramatically divided into 2 categories: that which might end in an if statement that has no else block(short if statement) and those that definitely do not.Only those that definitely do not end in a short if statement may appear as an immeadiate substatement
before the keyword else in an if statement that does not have an else clause
-------------------------------------------------

Am confused about this
Can someone help please
Thanks


Sunita<br />SCJP 1.4
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
I'm confused because I can't find this in the JLS. 14.7 deals with labeled statements. Do you have a link so I can see this in context?


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
I found it... it's actually 14.5.

"Only statements that definitely do not end in a short if statement may appear as an immediate substatement before the keyword else in an if statement that does have an else clause."
We see in the above example a violation of the statement above. The sub-if is trying to be a short-if but it can't because the the main-if's else statement gets assigned to the short if. In other words the above code gets turned into:

The solution around this problem is the proper use of braces to identify where the if-else statements belong.
sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
I am sorry.. it is under 14.5 in the chapter "Blocks and Statements" under the heading "Statements" in the last before paragraph...
Thanks.
sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
Thanks Thomas..
 
GeeCON Prague 2014
 
subject: If doubt