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 126247 - Equals method generation should include this != other
Summary: Equals method generation should include this != other
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All Windows XP
: P3 blocker (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-30 07:11 UTC by cbr600f
Modified: 2013-09-02 14:22 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cbr600f 2008-01-30 07:11:00 UTC
Equals method generation, although giving the option to include "fields" from current class, should always (or maybe
give the option) to check self equality.

Also would be nice if it uses single return but that'll be another enhancement...

#pseudocode
public boolean equals(Object arg) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }

        final T other = (T) obj;

#proposal to include this:
   if (this != other) {
   
   #now folows the current functionality
        #foreach field included
        if (this.#field != other.#field && (this.#field == null || !this.#fieldequals(other.id))) {
            return false;
        }

#end of new if included
   }
        
        return true;
    }

}
Comment 1 cbr600f 2008-01-30 07:17:42 UTC
The idea to include this behind comes for collections checking for equality of it's members, under a JPA aproach, most
of times JPA Beans have an autogenerated ID, so they will remain "equaled" each other, since it's id field has not been
generated yet but they're not the same object.

class Order {
   private List<OrderLine> lines;
   
   public void addLine(OrderLine newLine) {
     if (!lines.contains(newLine) { //this should have equals improved, specually for unmanaged JPA entities
        lines.add(newLine);
     }
   }
}

There are also more cases where this will be a great enhacement, this is provided only as example.