[ 
https://issues.apache.org/jira/browse/DERBY-5035?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12995318#comment-12995318
 ] 

Knut Anders Hatlen commented on DERBY-5035:
-------------------------------------------

I took a quick look at the patch and noticed that many of the changed classes 
inherited hashCode() methods from their super-classes, and that the inherited 
methods satisfied the requirement x1.equals(x2) --> x1.hashCode() == 
x2.hashCode(), even when the sub-class had overridden the equals() method.

The equals() methods in many of the changed classes essentially just do:

    return super.equals(other) && <some-other-condition>;

In these cases, if we decide to override the hashCode() method, we should use 
super.hashCode() as a component when computing the new hash code. For example, 
in TruncateOnCommit.java, the suggested new hashCode() method only returns 0 or 
1, which wouldn't work very well in a hash table. If it had used 
super.hashCode() there would be more variation in the returned hash values.

> [patch] equal objects should have equal hashcodes
> -------------------------------------------------
>
>                 Key: DERBY-5035
>                 URL: https://issues.apache.org/jira/browse/DERBY-5035
>             Project: Derby
>          Issue Type: Improvement
>          Components: Network Server
>    Affects Versions: 10.7.1.1
>            Reporter: Dave Brosius
>            Priority: Trivial
>             Fix For: 10.8.0.0
>
>         Attachments: equals_hashcode.diff
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> equal objects should have equal hashCodes otherwise they don't work correctly 
> in hash collections.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to