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 233395 - 'Insert Code'/hashCode and equals() changes
Summary: 'Insert Code'/hashCode and equals() changes
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.3
Hardware: PC Linux
: P3 normal (vote)
Assignee: Svata Dedic
Depends on:
Reported: 2013-07-25 09:49 UTC by tomzi
Modified: 2013-09-02 14:21 UTC (History)
0 users

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description tomzi 2013-07-25 09:49:25 UTC
For the hashCode Builder please currently it will be generates like this:

        int hash = 3;
        hash = 97 * hash + Objects.hashCode(this.var1);
        hash = 97 * hash + Objects.hashCode(this.var2);
        return hash;

.) please make the 97 to be exported into a variable;
.) Add a 'hash = super.hashCode()' in the beginning  if the current object extends from another one.

Same for equals()

Product Version = NetBeans IDE 7.3 (Build 201302132200)
Operating System = Linux version 3.8.0-26-generic running on amd64
Java; VM; Vendor = 1.7.0_25
Runtime = Java HotSpot(TM) 64-Bit Server VM 23.25-b01
Comment 1 Jan Lahoda 2013-07-30 15:03:18 UTC
I guess it would not harm anything (and would help to improve code quality as seen by automated checkers) to add a variable for the multiplier.

I would personally be very careful not to encourage overriding (non-default) equals&hashCode, so I would generally vote for not generating the super call - if the user needs that, then its simple to do manually, and it is more probable the user will ensure the sub- and super-class play nicely together when doing this manually.
Comment 2 tomzi 2013-08-12 08:14:18 UTC
Hmmm, good point, maybe for the sake of quicker implementation you could add an uncommented 
// hash = super.hashCode()

Then you just need to uncomment it if you want it :)