O'Reilly logo

Special Edition Using Java 2 Standard Edition by Geoff Friesen, Chuck Cavaness, Brian Keeton

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

Inspecting a Class for Its Methods

The previous examples have focused on constructors, but Reflection also allows you to discover the regular methods a class declares. This functionality is again provided by java.lang.Class.

Obtaining a List of Methods

Going back to the Requestor/Provider example used in Listing 28.1, a few simple changes allow the methods of a class to be queried and displayed along with its constructors. Listing 28.6 shows the necessary modifications.

Code Listing 28.6. Reflection Reveals Methods as Well as Constructors
 /* * Requestor */ import java.lang.reflect.*; public class Requestor { public void requestConstuctors() { try { // load the Provider class and use Reflection // to get an array of constructor information Class ...

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