Reputation: 7799
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)...
Upvotes: 66
Views: 24249
Reputation: 1086
33. if (1==1) return;
34. System.out.println("Hello world!");
It works in other languages too. But ByteCode without row 34.
Upvotes: 4
Reputation: 4290
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
Upvotes: 0
Reputation: 181460
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.
Upvotes: 128
Reputation: 8540
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.
Upvotes: -12
Reputation: 5316
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?
Upvotes: 3