O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Determining the Interfaces Implemented by a Class

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required