Sunday, May 15, 2011

equals() vs ==

Object class has a default method which looks like this :

public boolean equals(Object other)
return this==other;

== tests identity of the object, i.e. whether the 2 references are pointing the same object or not.

The default implementation of equals() is based on the == operator: Two objects are equal if and only if they are the same object. Naturally, most classes should define their own alternative implementation of this important method.

No comments:

Post a Comment