class A{
public A(){
System.out.println("in A");
}
}
public class SampleClass{
public static void main(String[] args) {
A a = new A();
System.out.println(A.class.isInstance(a.getClass()));
}
}
Output:
false
Why is it false? Both A.class and a.getClass() should not return the same class!
And in which condition we will get true from the isInstance() method?
Because
a.getClass()returnsClass<A>, but you should pass in anA:If you have two
Classinstances and want to check for assignment compatibility, then you needto use
isAssignableFrom():