2017  Kodetalk | Feedback | Privacy Policy | Terms | About

what is the difference between isinstance and isassignablefrom in java

When we say like below 


So what is the differences between these. 


class.isInstance(obj) is for checking an instance and returns true when the parameter obj is non-null and can be cast to class without raising a ClassCastException. In other words we can say the obj is an instance of class or its subclasses. class.isAssignableFrom(Some.class) will return true if class is the same as, or a superclass or superinterface of, Other. Other can be a class or an interface. It answers true if Other can be converted to a class.

Answer is