This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 247419 - Update code gen for "equals" to include object compare for "this"
Summary: Update code gen for "equals" to include object compare for "this"
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.0.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-23 18:48 UTC by SirIntellegence
Modified: 2015-09-25 09:51 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description SirIntellegence 2014-09-23 18:48:00 UTC
When one has the IDE generate an equals method, it spits out something like this:
@Override
public boolean equals(Object obj) {
	if (obj == null) {
		return false;
	}
	if (getClass() != obj.getClass()) {
		return false;
	}
	final Foo other = (Foo) obj;
	if (this.bar != other.bar) {
		return false;
	}
	return true;
}

I noticed that it is missing a comparison to "this", in other words:
if (this == obj)
    return true;
This could save processor time comparing members if the programmer doesn't add it themselves
Comment 1 SirIntellegence 2015-01-05 16:26:36 UTC
Bug still exists in 8.0.2
Comment 2 Dusan Balek 2015-09-25 09:51:45 UTC
Already fixed in the current dev build.