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.

Comments

Popular posts from this blog

Whitelist an Azure firewall IP using PowerShell

Excel: highlighting a row or a column based a value, the current date example.