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.
Thomas Hawtin - 06 Nov 2005 08:46 GMT
> 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?
What does the documentation say?
http://download.java.net/jdk6/docs/api/java/util/Collection.html#contains(java.l
ang.Object)
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Chris Uppal - 06 Nov 2005 09:37 GMT
> 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