override equals | Sololearn: Learn to code for FREE!


override equals

Is it correct that if i override equals in the subclass i need to use getClass instead of instanceof to keep the symetry? Are there othercases? Should i prefer all the time getClass() != obj.getClass() over this instanceof obj ?

1/19/2021 5:02:00 PM

Manfred h

2 Answers

New Answer


This is difficult to answer without seeing the code, if your just extending a class overriding the method in parent should be fine.


@D_Stark https://code.sololearn.com/ca0a2450a25A/# on oneside it gives me true but on the other false