Is there a way to ignore the 'Unreachable statement' error?
JavaJava Problem Overview
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)...
Java Solutions
Solution 1 - Java
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.
Solution 2 - Java
33. if (1==1) return;
34. System.out.println("Hello world!");
It works in other languages too. But ByteCode without row 34.
Solution 3 - Java
It isn't possible to ignore this error since it is an error according to the Java Language Specification.
You might also want to look at this post: https://stackoverflow.com/questions/2141029/unreachable-code-error-vs-dead-code-warning-in-java-under-eclipse
Solution 4 - Java
If you want disable/enable certain piece of code many times trick from old C may help you:
some_code();
more_code();
// */
/*
some_code();
more_code();
// */
Now you need only to write /*
at the beginning
Solution 5 - Java
you have to fix that unreachable code.
public void display(){
return; //move the return statement to appropriate place
int i;
}
compiler will not compile your source code. you have to take care of your source code that every line is reachable to compiler.