Originally posted by Deepak Jain:
Yes thats correct. But if the variable is a final variable then its guraenteed that its value will never change and hence the compiler should give a compile time error in Gurpeet's second case.
That seems true to our human reasoning, but isn't the case for the Java compiler. As the JLS excerpt that Jan posted says, Java will only carry out a very specific and
conservative flow analysis algorithm to determine reachability. It's conservative in the sense that it's not exhaustive--not every statement that is really unreachable will be flagged as unreachable by the algorithm.
Read the JLS excerpt again, and observe that it provides an example of a code fragment containing a line that we humans know is unreachable, but which the flow analysis algorithm will not flag as unreachable.