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



Ask a Question

Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Rattling explanation .....thnx brother
View Tutorial          By: zorro at 2011-06-16 05:05:43

2. Sir , I am doing B.Tech . I want to know more abou
View Tutorial          By: amita saini at 2011-08-05 13:07:35

3. Thanks - very useful!
View Tutorial          By: Adam Musial-Bright at 2010-02-28 06:14:39

4. Very nice article.. thanks
View Tutorial          By: Basu at 2010-05-29 05:52:00

5. Thanks a lot lot lot for this... u saved me...
View Tutorial          By: Sourabh Idoorkar at 2011-06-10 04:25:10

6. i dont understand
View Tutorial          By: amabelle pascual at 2014-01-09 23:47:14

7. very easy to understand ... a quite a good example
View Tutorial          By: Dinesh at 2012-09-22 18:19:45

8. Dear Samantha, Thx for pointing the extra \. I hav
View Tutorial          By: Emiley at 2011-06-06 04:50:40

9. Thanks mate !!!

-- Anish Sneh

View Tutorial          By: Anish Sneh at 2010-08-18 07:42:56

10. The Compleate Reference
JAVA Seventh Editi

View Tutorial          By: joshap at 2014-10-25 12:05:41