String hashCode

Cedric Berger cedric@wireless-networks.com
Wed Jan 31 16:41:00 GMT 2001


>> I'd prefer to simply add a hashcode field, but only set it if hashcode() is
> called or the string gets interned. But, as you point out, there is the
> problem of how to determine whether the value has been set or not.
>> It would seem reasonable to set it to null or some other unlikely value
> initially, then bump it if the string just happens to hash to the same value
> - but this would violate the published spec of String.hashCode.
>A little variation: you could set 0 as a not-yet-calculated indicator, and
on the unlikely event the hashCode ends up 0, don't bump anything, just
return 0 and recalculate it next time...
Cedric


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /