I have a problem checking that one class inherits another.
I have the following code:
Class<Serializable> serializable = (Class<Serializable>) Class.forName("java.io.Serializable");
Class<String> stringClass = (Class<String>) Class.forName("java.lang.String");
System.out.println(stringClass.getClass().isAssignableFrom(serializable));
Serializable s = new String();
System.out.println("¿Porqueeeeeeeeee?");
As shown by line 4, string inherits from serializable, so I hope that isassignablefrom returns true.
I can not use instanceof
because I get the classes by reflection, and therefore I have to check it from the object Class