Answer the question
In order to leave comments, you need to log in
How to correctly implement the equals and hashCode methods for classes that inherit from each other in Java?
Suppose someone has developed class A and implemented the following equals method for it:
public boolean equals(Object arg) {
if (this == arg)
return true;
if(!(arg instanceof A))
return false;
return [сравниваем поля класса A]
}
Answer the question
In order to leave comments, you need to log in
Instead , you
should explicitly compare classes
. Plus, there is not enough check that arg is not null.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question