MyEclipse write Java code hint dead code reason

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.