java - While(false) causes unreachable statement compilation error -
i removing block of code our code base before release , used if(false) statement prevent execution:
if (false) { arraylist<string> list = new arraylist<string>(); ... }
this compiles fine , prevent execution of offending block of code (right or wrong, that's not current argument).
however, kind of accident, changed block above to:
while (false) { arraylist<string> list = new arraylist<string>(); ... }
and received unreachable statement compilation error.
i appreciate compilation error , understand reasons, however, i'm struggling comprehend difference between 2 blocks , why former compiles fine latter not when both have unreachable statements.
in both case compiler should raise error, because code between braces pointless, but if (false)
kept in java simulate c/c++ preprocessor #if 0
, quite common way of disabling parts of code testing or debugging.
edit: reference, "conditional compiling" detailed @ end of chapter 14.21 of java language specification.
Comments
Post a Comment