default equals function?

B

bob smith

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)

?
 
E

Eric Sosman

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.
 
J

Jeff Higgins

B

bob smith

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

(e-mail address removed)

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
 
E

Eric Sosman

[...]
Can someone tell me how the default equals function will behave?
[...]
Now all you need to do is go to the Javadoc and study what
Object's equals() will do.

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

... and there you have it. Any questions?
 
A

Arne Vajhøj

Here is a convenient dashboard to the Oracle Java documentation.
<http://docs.oracle.com/javase/7/docs/>
You may replace the 7 in the above address with a 3, 4, 5 or 6
to see older versions documentation.

And surprising that works (via redirect).

Surprisingly because Java SE 3 and 4 are J2SE 1.3 and 1.4!

Someone at Oracle has been smart.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top