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 66321 - Create toString, equals, hashCode according to Class fields
Summary: Create toString, equals, hashCode according to Class fields
Status: RESOLVED DUPLICATE of bug 60745
Alias: None
Product: editor
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 5.x
Hardware: All All
: P1 blocker with 5 votes (vote)
Assignee: issues@java
Depends on:
Reported: 2005-10-09 07:54 UTC by sleepgod001
Modified: 2007-04-18 19:25 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 sleepgod001 2005-10-09 07:54:27 UTC

You can refer to issue 60745.

What do you say if you can create the functionality like this.

  public int hashCode() { 
    int hash = 1;
    hash = hash * 31 + someNonNullField.hashCode();
    hash = hash * 31 
                + (someOtherField == null ? 0 : someOtherField.hashCode());
    return hash;

You iterator all not-trasient members and generate the code, there have some
rules i believe you know as well. I list them here just for the safe side.

Calculate hashcode for data type
long, calculate (int)f ^ (f >>> 32)) 
float, Float.floatToIntBits(f) 
double, Double.doubleToLongBits(f)
Object, if is null, =0, or return its own hashCode()

Same thing to equals() and toString().

It would be a great help if you can apply it.

Comment 1 rptmaestro 2006-06-26 15:41:21 UTC
Here is a look at what the competition provides in this area:
Comment 2 Jan Becicka 2007-04-18 19:25:46 UTC

*** This issue has been marked as a duplicate of 60745 ***