equals operator and a graph node

M

Monty Hall

Hello,

Suppose I have an object that's a vertex in a graph. Supppose I have a
vector that contains this vertex. Suppose I use the vector's
contain(Object) method. Does java first compare by memory reference ? Or
does it do a "deep" equals?

Monty.
 
C

Chris Uppal

Monty said:
Suppose I use the vector's
contain(Object) method. Does java first compare by memory reference ? Or
does it do a "deep" equals?

It uses the object's equals() method which by default is the same as comparing
by ==, but may be overridden to do a more meaningful comparison. So the answer
is that it depends on the objects in question.

Incidentally, this is specified in the JavaDoc for java.util.Vector.contains(),
though I admit it doesn't exactly jump out at you when you read it.

-- chris
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top