Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Did the sort do anything? Date: Tue, 17 May 2011 07:19:31 -0400 Organization: albasani.net Lines: 40 Message-ID: References: <9303hcFq0nU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net XFUa7Js5v3g+leJQ2Dqemoo+gSrj1TNxGnWeJ1ZrbrSK6WtQTcavqLp1v+juHDJOXAsIs5NDDYzBQaClsFVk0g== NNTP-Posting-Date: Tue, 17 May 2011 11:19:19 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="mslNNuYXkMqiu5E1VgaltrcqtnxYzum7Eb8XSOPajZDddAeNrZePTwn7nNCrkoFkoxK2jfY2iYlrt1xgyL8ME/tmDTQYbHawNRLehfmVrCCKxgJCFDVtpZh2VQocdP1k"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:IwTdsD23a4Hm9npMMnZcU2EZPBc= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4201 Patricia Shanahan wrote: > Lawrence D'Oliveiro wrote: >> Patricia Shanahan wrote: >>> Lawrence D'Oliveiro wrote: >>>> Patricia Shanahan wrote: >>>>> System.identityHashCode(x) does not necessarily return the same as >>>>> x.hashCode() ... >>>> It says it does >>>> : >>>> >>>> >>>> The hash code returned is the same one that would be returned by the >>>> method java.lang.Object.hashCode(), whether or not the object's >>>> class has overridden hashCode(). >>> My sample program output showed both x.hashCode() and >>> System.identityHashCode(x) for x referencing an Integer. The values were >>> different, because Integer overrides hashCode. >> How odd, because the above documentation says otherwise. > The way I interpret it, and the way it works in practice, and the way it's documented > is that System.identityHashCode(x) returns the value that would be returned by > x.hashCode() if the object referenced by x had inherited the Object > implementation of hashCode, regardless of whether x in fact uses an > overridden hash code. In other words, Laramie, 'x.hashCode()' can be different from 'Object#hashCode()'. It's called a "method override", and the point of 'System.identityHashCode()' is to ignore any possible override of 'Object#hashCode()' and just use the base version. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg