Strange generated hashCode() ?

Hi,

When you press alt-insert, and choose hashCode(), the default[1]
template first calls super.hashCode().
I think it's a problem when the super class is Object!
If the hashCode depends on Object.hashCode() implementation then two
hashCodes will be different even if the objects have the same attribute
values.
Does anybody else think it's a problem?

Thanks

BoD


by the way, is there a way to change the template?

4 comments
Comment actions Permalink

BoD wrote:

If the hashCode depends on Object.hashCode() implementation then two
hashCodes will be different even if the objects have the same attribute
values.


Yep, that's a problem but I haven't observed this behavior in the latest Irida
builds. For classes that are directly derived from Object IDEA doesn't insert
a super.hashCode() into the code. Which build/version are you referring to?

by the way, is there a way to change the template?


No, there's not. However, there's the ToString-plugin that can generate code based
on user-defined templates. There's also a request you could vote for:
http://www.jetbrains.net/jira/browse/IDEABKL-2880

HTH,
Sascha

0
Comment actions Permalink

My mistake. It works as you say if the object is directly derived from
Object.
I voted for this request.

BoD

Sascha Weinreuter wrote:

BoD wrote:

>>If the hashCode depends on Object.hashCode() implementation then two
>>hashCodes will be different even if the objects have the same attribute
>>values.


Yep, that's a problem but I haven't observed this behavior in the latest Irida
builds. For classes that are directly derived from Object IDEA doesn't insert
a super.hashCode() into the code. Which build/version are you referring to?

>>[1] by the way, is there a way to change the template?


No, there's not. However, there's the ToString-plugin that can generate code based
on user-defined templates. There's also a request you could vote for:
http://www.jetbrains.net/jira/browse/IDEABKL-2880

HTH,
Sascha

0
Comment actions Permalink

My mistake. It works as you say if the object is directly derived from Object.
I voted for this request.


Actually the rule is that it will/should only add super.hashCode() if your class
is derived from a class that overrides hashCode().

Sascha

0
Comment actions Permalink

Sascha Weinreuter wrote:
>>My mistake. It works as you say if the object is directly derived from Object.
>>I voted for this request.


Actually the rule is that it will/should only add super.hashCode() if your class
is derived from a class that overrides hashCode().

Sascha


That is a good rule, unless some (stupid) class overrides hashCode with
return super.hashCode();

:)

BoD

0

Please sign in to leave a comment.