Received: by 10.66.82.2 with SMTP id e2mr1546942pay.20.1346452403196; Fri, 31 Aug 2012 15:33:23 -0700 (PDT) Received: by 10.68.225.234 with SMTP id rn10mr2138827pbc.3.1346452403181; Fri, 31 Aug 2012 15:33:23 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!newsfeed.news.ucla.edu!usenet.stanford.edu!4no1206428pbn.1!news-out.google.com!a8ni4210pbd.1!nntp.google.com!4no1206426pbn.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Fri, 31 Aug 2012 15:33:22 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T NNTP-Posting-Host: 69.28.149.29 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> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: hashCode From: Lew Injection-Date: Fri, 31 Aug 2012 22:33:23 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.java.programmer:18489 On Friday, August 31, 2012 8:56:50 AM UTC-7, Jim Janney wrote: > 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. But it does impose a need for the hash function to access a private method so that it can return that value faster. Denying access to the private member would kill that optimization, one that any type of immutable object might want to use. That is the motivation for requiring access to private members. Your anger is misplaced, as your recent post rejects that scenario, implying that the only reason to use private members in 'hashCode'-alikes is for calculation of the value. -- Lew