Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can I write a method that delivers dynamically (at run time) all public methods of an object?

0
Posted

Can I write a method that delivers dynamically (at run time) all public methods of an object?

0

Ans : Don’t write this yourself; use the getMethods method in class Class, available in the JDK 1.1. The JDK 1.1 enhances the ability of class Class to inspect Java classes at run time, by means of classes in the java.lang.reflect package: • Method: instances of this class let you inspect and manipulate a specific method of a class. • Field: instances of this class let you inspect and manipulate a specific field of a class. • Constructor: instances of this class let you inspect and manipulate a specific constructor of a class. Following are several of the new (1.1) methods in class Class: • getMethods(): returns an array of Method objects corresponding to the public methods of this class. • getFields(): returns an array of Field objects corresponding to the public fields (variables) of this class. • getConstructors(): returns an array of Constructor objects corresponding to the public constructors of this class. Thus, inspecting methods, fields, or constructors at run time requires tha

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.