Originally posted by Brian Cole:
[QB][/QB]
Hi Brian and Nowak,
Thanks for giving me the reference to the JLS about the unusual behaviour of if statement with the constants true and false
Now i understood about the concept of reachability and unreachability issues of if statement
But i have one more little doubt
Consider the below code
int x;
if (true) { x=3; }
Now because of the unusual behaviour of if statement, the compiler can't (should not) decide whether statement x=3 is reachable or not. So it is not sure whether the variable x is initialized to 3 or not.
Suppose if we write the statement 'x++' or some other statment like 'System.out.println(x)' using the variable x, the compiler is not giving the error 'the local variable x may not have been initialized'.
I think the compiler should give this error because the compiler is not sure whether x is initialized or not because of the unusual behaviour of if statement with the constants true and false. ???