Say I have a class where I would have to check for multiple different types of objects. Would it be feasible/possible to override equals()
in the following manner?
public boolean equals(Object o){
if(o == null) return false;
if(o instanceof class1){
return this.class1.equals((class1) o);
if(o instanceof class2){
return this.class2.equals((class2) o);
...
}
Would this ever be useful? I assume here that I create a static overloaded equals()
method in the respective classes (though maybe polymorphism would take care of that automatically as long as I cast?).