db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-5035) [patch] equal objects should have equal hashcodes
Date Wed, 16 Feb 2011 14:36:57 GMT

    [ 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

> [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:
>            Reporter: Dave Brosius
>            Priority: Trivial
>             Fix For:
>         Attachments: equals_hashcode.diff
>   Original Estimate: 1h
>  Remaining Estimate: 1h
> equal objects should have equal hashCodes otherwise they don't work correctly in hash

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


View raw message