1. 程式人生 > >Is there something like instanceOf(Class c) in Java?

Is there something like instanceOf(Class c) in Java?

When using instanceof, you need to know the class of B at compile time. When using isAssignableFrom() it can be dynamic and change during runtime.

instanceof can only be used with reference types, not primitive types. isAssignableFrom() can be used with any class objects:

a instanceof int  // syntax error
3 instanceof Foo // syntax error int.class.isAssignableFrom(int.class) // true