The only reason to use getClass() rather than instanceof is that I would like to say that both compared references point to objects of the same class, and not to objects that implement the same base class.
Say we have Employee e and Manager m ( Employee continues).
m instanceof Employee will give true, m.getClass() == Employee.class will return false.
In some cases, the latter may be preferable, but rarely if instances are compared in the equals() or hashCode() methods.
jwenting
source share