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

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.

 
 
« February 2023»
SunMonTueWedThuFriSat
   1234
567891011
12131415161718
19202122232425
262728    
 
Links
 
Quote
« I needed a password with eight characters so I picked Snow White and the Seven Dwarves. »