File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

statement unreachable

 
Niral Trivedi
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,
Shouldn't following code give 'Statement Unreachable' compilation error for 'else' part??? Because variable 'boo' is always true!!! Instead it compiles and prints 'if' successfully!!!

Please help..
Thank you..
Niral
 
Meg Adal
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,
Shouldn't following code give 'Statement Unreachable' compilation error for 'else' part??? Because variable 'boo' is always true!!! Instead it compiles and prints 'if' successfully!!!
boo is variable means its value can changed any time anywere in the program
if boo were final boolean boo =true; you would get unreachable statement error as boo is final so its value can't be changed
[ September 06, 2002: Message edited by: Megan Adal ]
 
janus place
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if you have final boolean boo = true;
The else part will compile ok and the program will print out "if" successfully.
Instead of an if condition check, if you have a while loop, this will give compile error :
class Buggy {
public static void main ( String args [ ] ) {
final boolean boo = true ;
if ( boo ) {
System.out.println ( " if " ) ;
} else;

while (!boo){
System.out.println ( " while " ) ;
}
}
};
Compile error on printing while !!
HTH,
Janus
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The if construct has been spared from checking for unreachable statement. The reason being that some time developer wants to do conditional compilation. All other conditional constructs will be checked for unreachable statement and compiler will let you know...
 
Niral Trivedi
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all..
Niral
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic