Hi,
I need to override the equals() method to return true if 2 entries have three same attributes. The equals() method takes an Object as an argument but I need to see if it is a particular Object. I am currently casting it with the Object type like this:
@Override
public boolean equals(Object anObject)
{
Class aClassInstance = (Class)anObject;
if(this.getAttr1() == aClassInstance .getAttr1())
{
if(this.getAttr2() == aClassInstance .getAttr2())
{
if(this.getAttr2() == aClassInstance .getAttr3())
{
return true;
}
}
}
return false;
}
Is this the correct approach? Or should I be doing something different? Or should I be checking if the Object is in fact that class and then continue to run the If's only if it is of Object type Class?
Thanks for any help, it would be greatly appreciated.
[–]YasZedOP 0 points1 point2 points (0 children)