Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Did the sort do anything? Date: Tue, 17 May 2011 07:41:49 -0700 Organization: A noiseless patient Spider Lines: 28 Message-ID: References: <9303hcFq0nU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 17 May 2011 14:41:56 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="HywFvwzxyTvAIJCzdmb/Mw"; logging-data="20474"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KYCKPrrnrNQVrHiMepHy2yC9G56BYpHk=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:62sZQWtI6d1wj4YHcAf6ssmtloU= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4216 On 5/16/2011 2:11 PM, Lawrence D'Oliveiro wrote: > In message, 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(). Ouch, no. Newbie maneuver. Lots of info on this, but if you override equals(), you must override hashCode() because Object#hashCode() will not have the right semantics. Basically, in this case Object#hashCode() will return different hash codes for objects that compare equals() == true, and that breaks the contract. > Which brings us back to the point I made before, about whether the > sort key is computed from the entire value or not. Depends on the Comparator you are using.