Reflection: A New Way to Discover Information about Java classes
By Dan Becker2003-05-24
Querying Interfaces Using Java 1.02
The first improvement that you can make to the program is to list the interfaces a class implements as well as the classes it extends. This is done with the Class getInterfaces() method, which is available in Java 1.02 or later. The "Print Interfaces" loop added to the printTypes(...) method below recursively prints the types that a class implements.
|
This example also contains "pretty printing" code that indents the output and prints a label "class" or "interface" to distinguish the two. Notice that within the first print statement I have added the isInterface() method to perform this check. At this point, all methods used in the program are available in Java 1.02.
Tutorial Pages:
» Introduction
» Outlining the Class Hierarchy Using Java 1.02
» Querying Interfaces Using Java 1.02
» An Improved Java 1.02 Reflection Program
» Using the Reflection Features of Java 1.1: Modifiers
» Using the Reflection Features of Java 1.1: Fields
» Security Issues
» Conclusion
First published by IBM DeveloperWorks
