Java / Control Statements
Difference between dead code and unreachable code in Java.
Dead code is a compiler warning while unreachable code is a compile time error.
As per Java language specification, there must be some possible execution path from the beginning of the constructor, method, instance initializer or static initializer that contains the statement to the statement itself. The analysis takes into account the structure of statements. Except for the special treatment of
while, do, and for statements whose condition expression has the constant value true, the values of expressions are not taken into account in the flow analysis.
As per the JLS,
if statement is excluded so we get dead code warning.
More Related questions...