I have a parent class and in it I have equals
and I have other child classes of this parent class and I want to override equals
to compare private attributes of those child classes but I also want to use equals
of my father to compare the attributes inherited by my daughters, how would I do that without having to rewrite everything?
public class Pai {
String nome;
@Override
public boolean equals(Object obj) {
Pai other = (Pai) obj;
return(this.nome.equals(other.nome);
}
}
public class Filha extends Pai {
int atributoEspecifico';
@Override
public boolean equals(Object obj) {
// como comparo aquele atributo do meu pai também?
Filha other = (Filha) obj;
return this.atributoEspecifico == other.atributoEspecifico;
}
}