String hashCode
Jeff Sturm
jeff.sturm@commerceone.com
Wed Jan 31 16:49:00 GMT 2001
Cedric Berger wrote:
> 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...
That's reasonable. Zero happens to be the hashCode of an empty string, which
isn't unlikely at all, but is the cheapest of all strings to recompute.
Access to the hashCode field need not be synchronized since loads/stores are
guaranteed to be atomic on `int'. The main drawback is a larger String object.
--
Jeff Sturm
jeff.sturm@commerceone.com
More information about the Java
mailing list