This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: String hashCode
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