Java: "instanceof" does not work if the first parameter (object) is of type Class.
Problem:
instanceof does not work if the first parameter (object) is of type Class.
Solution:
Use the equivalent of "object instanceof Class", which is isAssignableFrom. For example, MyClass.class.isAssignableFrom(testClass) returns true if MyClass is a superclass or the same as the class of testClass.
instanceof does not work if the first parameter (object) is of type Class.
Solution:
Use the equivalent of "object instanceof Class", which is isAssignableFrom. For example, MyClass.class.isAssignableFrom(testClass) returns true if MyClass is a superclass or the same as the class of testClass.
Comments
Post a Comment