November 2006
Intermediate to advanced
224 pages
3h 29m
English
Class c = someObject.getClass(); Class[] interfaces = c.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { String interfaceName = interfaces[i].getName(); System.out.println(interfaceName); } |
In the previous phrase, we show you how to find the superclasses associated with a given class. Superclasses are related to inheritance and the class extension mechanism in Java. In addition to extending a class, in Java you can implement an interface. Through reflection, you can also find which interfaces a given class has implemented. After you’ve obtained a Class object, you can use the getInterfaces() method to get the class’s interfaces if indeed the class implements any interfaces. The ...
Read now
Unlock full access