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



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. The iterator returned by iterator() does not point
View Tutorial          By: Jeffrey at 2009-10-06 21:45:41

2. Hi

I want the java code for i

View Tutorial          By: Deepak at 2015-07-29 15:07:09

3. Sir!
I want the source code for receiv

View Tutorial          By: Anupam Shukla at 2010-04-30 00:09:25

4. i have run the program..bt there r so many excepti
View Tutorial          By: ayan at 2010-05-26 10:37:51

5. Can you please tell me about parameter and validat
View Tutorial          By: Atul at 2010-09-08 04:48:00

6. very good example...........
View Tutorial          By: debojit dey at 2010-07-20 15:48:38

7. This the very good introduction to the J2ME for th
View Tutorial          By: chetan jain at 2010-04-01 06:39:32

8. Thank you, saved my life
View Tutorial          By: Zs at 2013-04-13 22:51:54

9. DON'T USE GETS!!!!!!!!!!!!!!! IT'S DANGEROUS!
View Tutorial          By: Caterpillar at 2012-04-23 13:22:42

10. Thanks, it worked.
View Tutorial          By: Deepak Varier at 2009-08-19 03:38:07