using a cast in an overriden equals method should I use generics and if so, how? here is my issue when trying to override my equals method. 

this is what I have currently

 @Override
public boolean equals(Object o) {
 if (this.name.equals(((Animal) o).getName())) {
  System.out.println("True");
return true;
} else {
 System.out.println("False");
 return false;
 }

}


I'm trying to compare the names of objects which extend the Animal class is there a better way to create this equals method without the explicit casting to compare the names of each object?, I was messing around with Generics but just couldn't get it to work properly. below is what I attempted with generics but when I tried to pass an object in the parenthesis it was just using the super equals method. (The get method literally just returns the name)

public boolean equals(Class&lt;? extends Animal&gt;o) {
 if (this.name.equals(o.getName())) {
   System.out.println("True");
   return true;
} else {
   System.out.println("False");
   return false;
  }

}


any help is really appreciated.
You could try something like the following in The Animal Class:

 @Override
   public boolean equals(Object obj) {
      Animal animal = null;
      if(obj == null || this ==null) {
         return false;
      }
      if(obj instanceof Animal) {
         animal = (Animal) obj;
      }
      if(this.name.equals(animal.getName())) {
         return true;
      }

      return super.equals(obj);
   }


Now if you have a Cat and a Dog which extend Animal
and you check

private Cat cat = new Cat("Pipsy");
private Dog dog = new Dog("Pupsy");


if(cat.equals(dog)) will return false because you check the name, and they have a different one.

I do not think you have to use Generics, Object is generic enough :). Hope this helped