Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: default equals function? Date: Thu, 09 Aug 2012 18:11:07 -0400 Organization: A noiseless patient Spider Lines: 32 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 9 Aug 2012 22:11:11 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="ffb8f7085759b339c1002252b48331a4"; logging-data="20008"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xTOc9jlIqGuipJK9p8MF1" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: Cancel-Lock: sha1:tH836cwZxLPv3adYoyFdL3GGPVc= Xref: csiph.com comp.lang.java.programmer:17569 On 8/9/2012 5:58 PM, bob smith wrote: > Let's say I have a class like this: > > public class Kern_Pair { > int letter1, letter2; > > } > > Can someone tell me how the default equals function will behave? > > like > > kernpair1.equals(kernpair2) > > ? Teachable Moment. The Kern_Pair class has no equals() method of its own, so it inherits equals() from the nearest superclass that has one. Walk up the class inheritance tree to find the nearest ancestor with an equals(). The class inheritance tree for Kern_Pair is fairly short: Its immediate superclass is Object (because you didn't say "extends SomethingElse"), so the equals() method for Kern_Pair *is* the equals() method of Object. Now all you need to do is go to the Javadoc and study what Object's equals() will do. -- Eric Sosman esosman@ieee-dot-org.invalid