Check if an object is an instance of a class (but not an instance of its subclass)

If you have to do this, the only way would be the getClass().equals(Foo.class) option you’ve suggested.

However, the goal of OO design is to allow you to treat any Foo in the same fashion. Whether or not the instance is a subclass should be irrelevant in a normal program.

Leave a Comment