You just need the instanceof check.