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. what about object bean with view scope ??
View Tutorial          By: abdelaziz akharraz at 2012-10-09 15:06:52

2. Thanks, Just what i was looking for.
View Tutorial          By: Baapu at 2009-10-21 15:21:43

3. hey good code woww. this code lot of help me much
View Tutorial          By: vaibhav malpani at 2015-03-25 05:48:50

4. The above code works for me. When I run the progra
View Tutorial          By: Avinash at 2011-12-01 10:20:19

5. i see that lots of people get this exception : jav
View Tutorial          By: oded at 2008-09-28 03:33:33

6. good
View Tutorial          By: pardhuman at 2011-06-24 08:18:15

7. It can be Made Popular by adding Links or Suggesti
View Tutorial          By: Ramalingam at 2010-03-20 23:00:41

8. i tried, the coding dont hv any errors but its not
View Tutorial          By: anna at 2010-11-02 21:56:27

9. This example is working fine....I think BillGates
View Tutorial          By: Monoj Rath at 2010-07-15 01:27:51

10. when i am trying to compile your program one error
View Tutorial          By: anindya at 2011-11-23 03:00:49