Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: hashCode Date: Fri, 31 Aug 2012 09:56:48 -0600 Organization: more research is needed Lines: 33 Message-ID: References: <563f186a-edb3-4311-ae48-3af7decfce2c@googlegroups.com> <5028191b$0$290$14726298@news.sunsite.dk> <50317b03$0$281$14726298@news.sunsite.dk> <503bfd0f$0$282$14726298@news.sunsite.dk> <3zc%r.5945$pd4.2658@newsfe21.iad> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="75975abe3fe3503ca7350803ab98e478"; logging-data="28702"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186KdVoN0XsDLACf80WMHeE" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:ctf4370e4gU+RRF40qR3ueiAvc8= sha1:UzinjJVpq+2YH3N9mh0GYYH/U2c= Xref: csiph.com comp.lang.java.programmer:18478 Eric Sosman writes: > On 8/31/2012 11:08 AM, Jim Janney wrote: >> Daniele Futtorovic writes: >> >>> On 31/08/2012 03:43, Eric Sosman allegedly wrote: >>>> On 8/30/2012 6:52 PM, Daniele Futtorovic wrote: >>>> [...] >>>> As an example of why a hasher might want access to a strictly-private >>>> field, I offered String: [...] >>> >>> Imposing that classes should expose all information "relevant" (says >>> who??) to hashing is utter rubbish IMNSHO. >> >> Objects that compare equal must hash to the same value. It follows that >> if the hash function uses a value, so must the comparison method. > > Since java.lang.String had already been mentioned, it's sort > of too bad you didn't look at it before posting. Had you done so, > you'd have found that [1] hashCode() uses the private field `hash' > and [2] equals() does not. If you want to play gotcha, it's sort of too bad you don't read this newsgroup more often. I pointed out the use of the private field some time ago, when we were discussing immutable classes. If you'd rather argue on the actual issues, a cached result is not extra information. The hashCode method in String doesn't return anything that can't be computed from publically available information. -- Jim Janney