Getting Constructor and Method Information with Reflection

Just as you can get information on class attributes and data members, you can use the Reflection APIs to get information on the methods of a class. The getConstructors() method returns a group of Constructor objects for each constructor in the class. The getMethods() method returns an array of Method objects, one for each method in the class.

Reflection of Constructor and Method Information: Code Example

Listing 13.2 shows how to get the methods and constructors for a class. As with fields, you can obtain the modifiers for a constructor or method, and the parameters as well. You could then use this information to create an instance of the class or call a method on an instance of the class. ...

Get PURE Java™ 2 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.