aspose file tools*
The moose likes Java in General and the fly likes Compile time unreachability Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Compile time unreachability" Watch "Compile time unreachability" New topic
Author

Compile time unreachability

Geethakrishna Srihari
Ranch Hand

Joined: May 25, 2005
Posts: 30
The code

class Test
{
public static void main(String args[])
{
while(false||true)
{
}
int a=1;
}
}
o/p on compiling - unreachable statement int a=1;

But if we replace the || by |, it works fine? How does it work?
Erik Larson
Greenhorn

Joined: Apr 25, 2005
Posts: 10
Imagine the code is running. What will the while condition evaluate to? If you enter the loop, what happens next?


SCJP<br />SCJD - someday!
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
I get the error with | too. According to JLS both | and || versions should not compile. Both (false || true) and (false|true) are compile time constant expressions with value of true.
 
 
subject: Compile time unreachability