Connecting Tech Pros Worldwide Forums | Help | Site Map

Checking two different objects for equality

Newbie
 
Join Date: Nov 2007
Posts: 1
#1: Dec 12 '07
can we use two diffrent object of classes for check equlity of object and how?

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Dec 12 '07

re: Checking two different objects for equality


Quote:

Originally Posted by jyotishirsat

can we use two diffrent object of classes for check equlity of object and how?

HI, I changed your topic title because the old title was meaningless. You can
consider two different objects equal if you want; all you have to do is write the
appropriate equals() and hashCode() methods for them.

kind regards,

Jos
BigDaddyLH's Avatar
Moderator
 
Join Date: Dec 2007
Location: Kelowna, BC Canada
Posts: 1,212
#3: Dec 12 '07

re: Checking two different objects for equality


And example of this is for objects of type java.util.List. In the documentation of that interface it states:

Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal.
So, for example, an ArrayList can be equal to a LinkedList.
Reply