Some more excerpts from the same book(ObjectorientedDesignPatterns, by Cay Horstmann),
According to Horstmann, the perfect equals method is as below
pulic boolean equals(Object otherObject)
{
if(this==otherObject)
return true; //Many times equals is called on identical objects, then there is no reason
//to check for contents again
if(otherObject==null)//For any non null reference value x, x.equals(null) should return false
return false;
if(getClass()!=otherObject.getClass()//A different Class, obvious
return false;
-
-
-//desired equality conditions to be checked follows...
-
-
-
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment