Often use MyEclipse or Eclipse editor to write Java Program Ape code. You may often encounter a yellow cordon: Dead Code; General Program apes encounter these problems will be ignored, anyway, it does not affect the program's compilation run. Yes, this is not a bug, just a hint, for an obsessive-compulsive program ape, he has no problem with the code, including the Yellow line warning should be wiped out, here is a simple dead code is dead code, the reason for the lack of action and solution.
As the name implies, dead code. That is, you write the line is invalid code, optional, white is a line of nonsense; this is what you need to look at the processing logic of this line, may be redundant inference or other redundant code. For example, in the following cases:
1. Situation one: the useless condition inference is that you infer that the condition is always true
if (True & True) {
System.out.println ("execute OK");
} else {
System.out.println ("execute fail");
}
It is not useful to start from else.
The result is known because True&true is Yi. So the else part is useless, and the compiler knows the code that certainly won't run.
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 not sure whether A & B is constant at compile time.
2. Situation two: Redundant inference is that the object you infer is never empty; in fact, it is similar to the situation
Timelineeventmodel Datamodel = new Timelineeventmodel ();
if (datamodel!=null) {
Run some operations .....
}
The inference here is also superfluous, because you have new this object, the object will not be empty
Not to be continued. There may be some other cases of dead code. Wait until the time code met and then add it!
For now, the dead code hint is generally present if or other inferred conditions.
Reprint Please specify: Http://blog.csdn.net/yangkai_hudong
MyEclipse write Java code hint dead code reason