Programmers who frequently use the MyEclipse or Eclipse editor to write Java code may often experience a yellow line warning: Dead code; Ordinary programmers will ignore these problems, anyway, without affecting the execution of the program's compilation. Yes, this is not a bug, just a hint, for a programmer with obsessive-compulsive disorder, he has no problem with the code, including Yellow line warning to be eliminated, here a simple dead code that is dead, the reason for the role of code hints and solutions.
As the name suggests, dead code, that is, you write the line is invalid code, dispensable, is a line of nonsense; this is what you need to look at the processing logic of this line, which may be redundant or redundant, such as the following:
1. Situation one: the useless condition judgment, is you judge of this condition forever is true
if (True & True) {
System.out.println ("execute OK");
} else {
System.out.println ("execute fail");
}
Starting from else is no action.
Because the true&true is known as the result when it is being compiled, the else part is useless, and the compiler knows the code that will not be executed.
Into:
Boolean A = true;
Boolean B = true;
if (A & B) {
System.out.println ("execute OK");
} else {
System.out.println ("execute fail");
}
The problem does not occur because the compiler is unsure at compile time whether A & B is constant.
2. Situation two: superfluous judgment, that you judge of this object is never empty; Actually, it's similar to a situation.
Timelineeventmodel Datamodel = new Timelineeventmodel ();
if (Datamodel!=null) {
Perform some action ...
}
The judgment here is also superfluous, because you have new this object, then this object will not be empty
To be continued, there may be some other cases of dead code, wait until the code met to add it. At present, dead code hints generally appear in the condition of if or other judgments.
Reprint please indicate: Http://blog.csdn.net/yangkai_hudong