Java Class.isAssignableFrom(Class <?> cls)
Syntax
Class.isAssignableFrom(Class <?> cls) has the following syntax.
public boolean isAssignableFrom(Class <?> cls)
Example
In the following code shows how to use Class.isAssignableFrom(Class <?> cls) method.
/* w ww.j a v a 2 s. co m*/
public class Main {
public static void main(String[] args) throws Exception {
Main cls = new Main();
Class c = cls.getClass();
Class bClass = BaseClass.class;
boolean retval = bClass.isAssignableFrom(c);
System.out.println("Return Value = " + retval);
retval = c.isAssignableFrom(bClass);
System.out.println("Return Value = " + retval);
}
}
class BaseClass extends Main {
public BaseClass() {
}
}
The code above generates the following result.