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.