You cannot do it this way. Fortunately, you already have a Class<T>
argument so instead do
myClass.isAssignableFrom(obj.getClass())
This will return true if obj
is of class myClass
or subclass.
As @ILMTitan pointed out (thanks), you will need to check for obj == null
to avoid a potential NullPointerException, or use myClass.isInstance(obj)
instead. Either does what you need.