Java override Object equals() method

generics, java, object

Solution

You can cast it inside the method, just make sure that is of the right type using instance of

if(obj instanceof Person)
{
   Person otherPerson = (Person) obj;
   //Rest of the code to check equality
}
else
{
//return false maybe
}

Problem

How do I override the equals method in the object class? i.e I have ``` class Person{ //need to override here public boolean equals (Object obj){ } ``` I want to convert the parameter obj to a type Person, but if I do (Person) obj it won't work.

Original source