Hi
Can anybody comment on my observation ???
equal() method of object class will return true IFF
a) Both references are same?
b) Will return false even if the data is same but references are different?
Printable View
Hi
Can anybody comment on my observation ???
equal() method of object class will return true IFF
a) Both references are same?
b) Will return false even if the data is same but references are different?
The equals() method in the class Object uses only the == operator for comparisons so unless you override equals(), two objects are considered equal only if the two references refer to the same object.
What do you mean?Quote:
unless you override equals(), two objects are considered equal only if the two references refer to the same object.
If i override the equals() method, i can only get a "true" if both references are only in the same object?
If it is, it depends on the new implementation....
Equals is ok method. Why it belongs to Object class it's a question. You may need to check if 2 objects equals by content and not by references.
Hello skyineyes
Consider the variables A and B:
Mostly, we want to see if two objects are equal by value and not by reference. So then, we override the equals() method. In your question, both a and b are true. ;)Code:A.equals(B) is true [COLOR="RoyalBlue"][I]if and only if[/I][/COLOR] A and B references the same object.