Comment on Tutorial - equals( ) Versus == in Java By Mashoud



Comment Added by : Javin @ eclipse remote debugging

Comment Added at : 2011-04-09 06:50:44

Comment on Tutorial : equals( ) Versus == in Java By Mashoud
Here is my approach for writing equals() method from <a href="http://javarevisited.blogspot.com/2011/02/how-to-write-equals-method-in-java.html">How to write equals method in Java</a>

1) Do this check -- if yes then return true.
2) Do null check -- if yes then return false.
3) Do the instanceof check if instanceof return false than return false
4) Type cast the object; note the sequence instanceof check must be prior to casting object.
5) Compare individual attribute start with numeric attribute because comparing numeric attribute is fast and using short circuit operator so if first field does not match , don't try to match rest of attribute and return false.


View Tutorial