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 com
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.
33. if (1==1) return;
34. System.out.println("Hello world!");
It works in other languages too. But ByteCode without row 34.
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: Unreachable code error vs. dead code warning in Java under Eclipse?
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
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.