Backtrack:  
 
by lunarg on May 28th 2015, at 11:39

For debugging purposes, I often prematurely abort a function by adding a return statement in the middle of it. With most compilers this works flawlessly, accept with Java...

The Java compiler bums out with an unreachable statement error, and won't allow you to compile a class until all code is reachable within a function.

Luckily, you can trick the compiler by adding an if-statement that's always true:

if (1==1) return;

This way, as the return is supposedly conditional, and the compiler doesn't consider the result of an if-statement, it is tricked into believing the following code is still reachable.

 
 
« October 2024»
SunMonTueWedThuFriSat
  12345
6789101112
13141516171819
20212223242526
2728293031  
 
Links
 
Quote
« You only find out who is swimming naked when the tide goes out. »
Warren Buffett