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 60745 - Create toString, equals, hashCode
Summary: Create toString, equals, hashCode
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker with 3 votes (vote)
Assignee: Dusan Balek
: 66321 171541 (view as bug list)
Depends on:
Reported: 2005-07-05 17:35 UTC by zwollner
Modified: 2011-09-19 21:44 UTC (History)
1 user (show)

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description zwollner 2005-07-05 17:35:16 UTC
I think it would be very heplful if there was a tool that allowed easy creation
of some basic methods like: (toString, equals, hashCode).
creating thses three for almost every class is very time consuming, now I'm sure
everyone creates all these slightly different so if there were some sort of
template we could edit that would be very helpful.
Comment 1 zwollner 2005-08-15 16:47:11 UTC
also if anyone wants a copy of the project let me know, I'd be happy to email it
to you.
Comment 2 zwollner 2005-08-15 16:49:03 UTC
sorry that last comment was ment for another issue please ingnore it or delete it
Comment 3 Jan Becicka 2005-08-25 10:33:15 UTC
Ctrl-I does not work for you?
Comment 4 zwollner 2005-08-25 15:25:58 UTC
Well thanks, I never knew about that. But is there anyway to edit the template
or something, because the methods arn't like I need them to be.
Comment 5 sleepgod001 2005-09-19 10:31:20 UTC
I strongly agree this feature.

Ctrl+I do the work, but it only create an empty function.

What do you say if you can create the function like it.

  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 6 Jan Becicka 2007-04-18 19:25:02 UTC
Editor issue. Probably implemented...
Comment 7 Jan Becicka 2007-04-18 19:25:39 UTC
*** Issue 66321 has been marked as a duplicate of this issue. ***
Comment 8 Jan Lahoda 2007-04-19 12:42:43 UTC
equals and hashCode should be implemented as of NB6.0M8, AFAIK. toString is
still missing.
Comment 9 reister 2008-03-14 06:11:05 UTC
The toString code insert was in 5.5 (and maybe 5.0?), can't seem to find it in 6.
Comment 10 jaylogan 2010-12-05 12:41:43 UTC
*** Bug 171541 has been marked as a duplicate of this bug. ***