X-Received: by 10.66.72.232 with SMTP id g8mr812179pav.23.1355934294518; Wed, 19 Dec 2012 08:24:54 -0800 (PST) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!newsfeed.news.ucla.edu!usenet.stanford.edu!kr7no12546939pbb.0!news-out.google.com!6ni53430pbd.1!nntp.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 19 Dec 2012 10:24:54 -0600 Date: Wed, 19 Dec 2012 08:25:08 -0800 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Need clarification on Object.equals. References: <14r3pk5hnnuce.1fmlq04hracjd.dlg@40tude.net> <7f86e17c-72f6-4b87-948d-9ee8ad102390@googlegroups.com> In-Reply-To: <7f86e17c-72f6-4b87-948d-9ee8ad102390@googlegroups.com> Message-ID: <5f2dndzjy4LLd0zNnZ2dnUVZ_r2dnZ2d@earthlink.com> Lines: 25 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.205.210 X-Trace: sv3-WsyjBwSNum0fgWvdldcHD4jmP6AtbY6iOBMy0t3kZxQ4wQeMGXIfFZAp0siTb8GY9AK0qwLbUdsJ07m!5MC40eVrMaOs//+/6mL1gL+fVGRdamqypZ+KBymHPl19cv8LawJtq4glFI4yCJfSBdMQWYx4RpUq!MgpuM9tgckXL+PwkSDVgccBIQUN9Hwhfb0j/0sWYmFXpCuU= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2733 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Xref: csiph.com comp.lang.java.programmer:20547 On 12/19/2012 8: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: > On Tue, 18 Dec 2012 10:39:27 +0000, lipska the kat > wrote, quoted or indirectly quoted someone > who said : > >>> 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. > I think "inappropriately" might have been a better word than "incorrectly". The inherited .equals method was a fine .equals method for a Set. Indeed, it does exactly what a Set .equals method is required to do, according to the Set contract. The problem was that AbstractSet was being extended by a class that is apparently not intended to be used as a Set implementation. The inherited .equals method was not an appropriate .equals method for Node. Patricia