The naive solution is to put in an early return statement in the code. However, the Java compiler detects this and you get a compiler unreachable statement error. There is a way around this though!
Lets look at some code to illustrate this.
This code doesn't do anything useful, but for example purposes lets say we needed to return early from the method before the 'int k = i + j;' line was executed. We could try inserting a return statement like this...
Of course this would get a compile error...
int k = i + j;
So how do we trick the compiler in letting us return early? It's as simple as adding an invariant true condition to the return statement thus:
The condition inside the if statement will always evaluate to true (unless you're doing quantum computing maybe) so we will always execute the return statement and the compiler will not complain.
This is a trick and abuse of the language so it should not be used in normal programming situations, but under certain conditions this can make an invaluable debugging tool.