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.

Add a new comment
 
Your name:
Your e-mail:
Your comment:
 
Basic BBcode is supported.
Captcha:
Type the letters and numbers as shown.
/get/captcha/1715329251
Not readable? Get another.
 
 
 
 
« May 2024»
SunMonTueWedThuFriSat
   1234
567891011
12131415161718
19202122232425
262728293031
 
Links
 
Quote
« Debating Windows vs. Linux vs. Mac is pointless: they all have their merits and flaws, and it ultimately comes to down to personal preference. »
Me