Changing the hashCode() method to return toHashCode() per the request in LANG-520

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@829285 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-10-24 00:04:07 +00:00
parent 3d17fad6d6
commit 4f9c1c3777
2 changed files with 21 additions and 0 deletions

View File

@ -969,4 +969,16 @@ public int toHashCode() {
return iTotal;
}
/**
* <p>
* The computed <code>hashCode</code> from toHashCode() is returned due to the likelyhood
* of bugs in mis-calling toHashCode() and the unlikelyness of it mattering what the hashCode for
* HashCodeBuilder itself is.
*
* @return <code>hashCode</code> based on the fields appended
*/
public int hashCode() {
return toHashCode();
}
}

View File

@ -547,4 +547,13 @@ public void testReflectionObjectCycle() {
b.hashCode();
}
/**
* Ensures LANG-520 remains true
*/
public void testToHashCodeEqualsHashCode() {
HashCodeBuilder hcb = new HashCodeBuilder(17, 37).append(new Object()).append('a');
assertEquals("hashCode() is no longer returning the same value as toHashCode() - see LANG-520",
hcb.toHashCode(), hcb.hashCode());
}
}