I am building a library management application in Java.
I have an abstract class called Material
. It has an abstract method called equals
.
There is a subclass called Newspaper
and it of course implements equals
, with the exact same signature as equals
has inside Material
:
public <T extends Material> boolean equals(Class<T> elementoAComparar) {
if (this.getTitulo().equals(elementoAComparar.getTitulo()) && this.getFechaPublicacion().equals(elementoAComparar.getFechaPublicacion())) {
return true;
} else {
return false;
}
}
Java cannot resolve any of the methods of elementoAComparar
. They all exist in Newspaper
which does extend Material
.
I got some help on this thread of SO but I cannot make it really work.
I guess what I don't really get is how to use methods of a class which is working as a generic parameter.
I am sure this is really not that hard, but I have really little experience with Java, please don't be too hard on me :)
Thanks!