class A {} class B extends A {} class C extends A {} public class Test { public static void main(String[] args) { A a = new A(); B b = new B(); C c = new C(); //静态比较,类型必须在编译的时候知道 //判断对象是不是类或者其子类的实例 System.out.println(a instanceof A);//true System.out…
https://stackoverflow.com/questions/3949260/java-class-isinstance-vs-class-isassignablefrom 1. MyClass.class.isInstance(obj) is for checking an instance. It returns true when the parameter obj is non-null and can be cast to MyClass without raising a …