Re: hashCode() for Custom classes
Peter Duniho wrote:
On Fri, 18 Apr 2008 12:47:36 -0700, Patricia Shanahan <pats@acm.org> wrote:
I was responding to the claim that "0 is a very unusual hash code to
return".
I never made that claim. You left out the qualification of the
statement I made, a qualification that's just as important as the
statement itself.
Its truth is not at all obvious to me.
I stated that it is unusual, except for the exception that I described.
Since the only exception you offered as an example of it not being
unusual was identical to the exception I described, I don't see what
you've added.
....
Ahh. I thought you meant that even with that exception, 0 was still an
unusual hash code. Under that assumption, it seemed worth while giving
an example of a commonly used class with a very frequent value whose
hash code is zero.
If you are only saying that 0 is unusual barring classes like Integer
that have a common value with 0 as hash code, then I am inclined to
agree. However, that would not affect the usefulness, in any general
approach to hash code construction, of ensuring smooth handling of 0 as
hash code, because of cases such as zero-value Integer.
Patricia