And thus spoke Eric Sosman...
> Should be hashCode(), with an upper-case C.
Hash code returns an integer,
and due that it is limited (it is not CRC),
so a string like : "zzzzz" may have an exception.
> And thus spoke Eric Sosman...
>
[quoted text clipped - 3 lines]
>
> Flo
Lew - 12 Aug 2007 10:21 GMT
> Hash code returns an integer,
Please do not top-post (placement of your reply above the material to which
you're replying).
> and due that it is limited (it is not CRC),
What is the limitation that concerns you, and how does it cause trouble?
Why is CRC needed?
> so a string like : "zzzzz" may have an exception.
What sort of exception do you mean?
"Flo 'Irian' Schaetz" <iryan@gmx.de> wrote in message
And thus spoke Eric Sosman...
>>> hashCode()
By definition, a hash reduces information from a source (document, byte
sequence, ...). That is, in fact, the point of a hash code in the first
place. The reduced information set is easier to manipulate than the source
domain set, and by dint of being int, faster, too. Not to put to fine a point
on it, hash codes are a hack to compensate for human impatience.
This aside from their cryptographic utility, but that's not essential to
Object.hashCode().
So if you want a hash code, you want to reduce information. There's no point
in asking for a hash code that doesn't reduce information.

Signature
Lew
Lew - 12 Aug 2007 10:23 GMT
> Hash code returns an integer,
Please do not top-post (placement of your reply above the material to which
you're replying).
> and due that it is limited (it is not CRC),
What is the limitation that concerns you, and how does it cause trouble?
Why is CRC needed?
> so a string like : "zzzzz" may have an exception.
What sort of exception do you mean?
"Flo 'Irian' Schaetz" wrote
And thus spoke Eric Sosman...
>> hashCode()
By definition, a hash reduces information from a source (document, byte
sequence, ...). That is, in fact, the point of a hash code in the first
place. The reduced information set is easier to manipulate than the source
domain set, and by dint of being int, faster, too. Not to put too fine a
point on it, hash codes are a hack to compensate for human impatience.
This aside from their cryptographic utility, but that's not essential to
Object.hashCode().
So if you want a hash code, you want to reduce information. There's no point
in asking for a hash code that doesn't reduce information.

Signature
Lew
rossum - 12 Aug 2007 10:37 GMT
[Top posting changed]
>> And thus spoke Eric Sosman...
>>
[quoted text clipped - 5 lines]
>
>Hash code returns an integer,
Of course hashCode() returns an integer, that is what it does. If you
do not want an integer then do not use hashCode().
>and due that it is limited (it is not CRC),
If you want a CRC then use a CRC.
>so a string like : "zzzzz" may have an exception.
I am not clear what you mean here. On my system
"zzzzz".hashCode() returns 116425210
rossum
Joshua Cranmer - 12 Aug 2007 16:34 GMT
> Hash code returns an integer,
> and due that it is limited (it is not CRC),
> so a string like : "zzzzz" may have an exception.
If I understand you correctly, what you are trying to say is that for
very long Strings, hashCode will fail with an exception. That is not
true: hashCode will only fail on a null object (for different reasons);
and the hash code will always be integral but not necessarily positive
(which is true for all objects). If you want a guaranteed positive hash
code, then use Math.abs(obj.hashCode()).
In short: hashCode will always return (except for null objects) an
integral value for any Java built-in object (negating bugs) and should
do so for any Java object.
I don't understand what you mean by "limited", though.

Signature
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth