can some please explain why I'm not getting true for an answer since the equals method compares object contents Thanks in advance! class Value { int i; } public class EqualsMethod { public static void main(String args[]) { Value v1 = new Value(); Value v2 = new value(); v1.i = v2.i = 100;
You need to overridden the equal method from the Object class. The default equal method only compare reference value. Thus, v1.equals(v2) is the same as v1 == v2 which it is false. hope this help.
[This message has been edited by FEI NG (edited January 02, 2002).]
You need to override the equals method. Your Value class uses the Object class equals method which returns true if and only if the reference refers to the same object. See API javadoc. Oops, Fei hit the submit key before me. [This message has been edited by Jim Turk (edited January 02, 2002).]
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss