Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!news.albasani.net!.POSTED!not-for-mail From: Lars Enderin Newsgroups: comp.lang.java.programmer Subject: Re: Need clarification on Object.equals. Date: Wed, 19 Dec 2012 17:43:46 +0100 Organization: albasani.net Lines: 30 Message-ID: <50D1EEC2.6090607@telia.com> References: <14r3pk5hnnuce.1fmlq04hracjd.dlg@40tude.net> <7f86e17c-72f6-4b87-948d-9ee8ad102390@googlegroups.com> <50d1e9c7$0$289$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.albasani.net ppLhTfoOFWNwVyaltb+92q6DJCGzcmfu8ghZzefyLG2d1bfW2sENTKYSQmx5smF1/zGwhilRv+sX+WnPGrFk9udlSFkl5X+eG/ChLzytNzwre/+pZ3hABfjpooUMtg19 NNTP-Posting-Date: Wed, 19 Dec 2012 16:44:31 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="8eHkECiz2ssuw4vtOy46hjgSjfe4SMXkiBV4pNTLFnB3UNSA4ZnjKcuSaAoQtDE1uF95e49l81YUwEwtWtFlmSDyAYSk9rOC/c0IFfiR+C2DDo9FpSks3vmj4k+Gfl0i"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: <50d1e9c7$0$289$14726298@news.sunsite.dk> Cancel-Lock: sha1:gLW0troL2TseTKN4F0xUqQLxyNw= Xref: csiph.com comp.lang.java.programmer:20548 2012-12-19 17:22, Arne Vajhøj skrev: > On 12/19/2012 11:13 AM, FredK wrote: >> On Tuesday, December 18, 2012 10:56:19 AM UTC-8, Peter Duniho wrote: >>> On Tue, 18 Dec 2012 04:48:16 -0800, Roedy Green wrote: >>>>> Node a = new Gate(); >>>>> Monitor b = new Monitor(); >>>>> System.out.println(a.equals(b)); // --> prints 'true' >>>> Gate or one of its superclasses is implementing equals. >>> And doing it incorrectly, I'd say. >> >> Why would you think it was done incorrectly? >> For most classes, a.equals(b) is not the same as a==b. >> Think about string: >> string a = "abc"); >> string b = new string(a); >> Clearly a==b is false, but a.equals(b) is true. >> >> Usually the equals() method returns true if the internal state of both >> objects is the same. > > It is rather unusual to have objects of different classes considered > equals. > > Your example is different. Both Gate and Monitor were extensions of AbstractSet, and empty, which eventually led to Set#containsAll, and thus equals, returning true. -- Lars Enderin