File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Compile time unreachability" Watch "Compile time unreachability" New topic

Compile time unreachability

Geethakrishna Srihari
Ranch Hand

Joined: May 25, 2005
Posts: 30
The code

class Test
public static void main(String args[])
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

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.
I agree. Here's the link:
subject: Compile time unreachability
It's not a secret anymore!