getClass

The getClass method returns the class of the instance it is called on. This means that the result of calling .getClass() on a variable of type Foo could be Foo.class or the .class of any of its subclasses.

To safeguard against ClassCastException, at runtime the compiler modifies the return type of the method to Class<? extends Foo>.