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: Need clarification on Object.equals. Date: Tue, 18 Dec 2012 10:24:44 -0800 Organization: A noiseless patient Spider Lines: 21 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 18 Dec 2012 18:24:47 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="61282af8d6595e8d991edb5ac03d6e00"; logging-data="25733"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GOUHx65TcBu16AouMP1LmSmJ4B+v8LE4=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: Cancel-Lock: sha1:UaASqImDtZLvtYi53CbrF/l4bDI= Xref: csiph.com comp.lang.java.programmer:20459 On 12/18/2012 12:13 AM, plewto@gmail.com wrote: > Node a = new Gate(); > Monitor b = new Monitor(); > System.out.println(a.equals(b)); // --> prints 'true' ... > The underlying production code is a bit complex to include here. My This is a red flag. The code should not be so complex that you can't show us what is really going on. If it *is* too complex, then likely the issue is the complexity itself. However, I think Roedy zeroed in on the most likely cause. Your abstract class, Node (or some superclass), implements equals() *incorrectly* and is returning true when it should not. Probably Node() should not implement equals() at all. Show us the implementation of equals() for Node (and probably Gate too, that version of equals() could also be borked in the example you gave) and we'll point out the error.