Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: hashCode Date: Fri, 10 Aug 2012 10:13:14 -0700 Organization: A noiseless patient Spider Lines: 24 Message-ID: References: <563f186a-edb3-4311-ae48-3af7decfce2c@googlegroups.com> <50253324$0$291$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 10 Aug 2012 17:13:17 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="61282af8d6595e8d991edb5ac03d6e00"; logging-data="16636"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3xiYpmxuOdxXFFEDVAYPGRR/SYHZ83js=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: <50253324$0$291$14726298@news.sunsite.dk> Cancel-Lock: sha1:q5MGTntFD7b0+fXz8cCe86rybkE= Xref: csiph.com comp.lang.java.programmer:17581 On 8/10/2012 9:13 AM, Arne Vajhøj wrote: > On 8/10/2012 11:47 AM, bob smith wrote: >> Is it always technically correct to override the hashCode function >> like so: >> >> @Override >> public int hashCode() { >> return 1; >> } > > It meets the minimum contractual obligation for that method. > > But performance of anything using the hash capability (like HashMap<>) > would be very bad. > >> Would it be potentially better if that was Object's implementation? > > It has a different behavior that may not be valid if you override equals. I think at this point we are doing Bob's homework for him.