Is it possible to somehow ignore this error? I find it much easier to just put return
in front of the code I don't want to run than to comment it (when the comments overlap and behave badly)...
If you keep any statements after the return statement those statements are unreachable statements by the controller. By using return statement we are telling control should go back to its caller explicitly .
The Unreachable statements refers to statements that won't get executed during the execution of the program are called Unreachable Statements. These statements might be unreachable because of the following reasons: Have a return statement before them. Have an infinite loop before them.
Unreachable code error occurs when the code can't be compiled due to a variety of reasons, some of which include: infinite loop, return statement before the unreachable line of code.
No. It's a compile time error. So you must get rid of it before running your class.
What I usually do is put a fake if
statement in front of it. Something like:
if(true) return; // unwanted code follows. no errors. i++; j++;
With this code, you will not get a Unreachable statement
error. And you will get what you want.
33. if (1==1) return; 34. System.out.println("Hello world!");
It works in other languages too. But ByteCode without row 34.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With