if(false) vs. while(false): unreachable code vs. dead code

The JLS section on unreachable code explains the rationale. Essentially, Java normally shouldn’t use conditional compilation like C routinely does with #ifdef, but there are some situations (such as debugging, and in particular backward binary compatibility) where allowing the compiler to entirely strip out code is needed, and so the specific construct if(false) is permitted for that purpose.

Leave a Comment