List methods of a class using Reflection



In this example we use the Reflection api to obtain the methods of a particular class called Person, which is an inner class.
First we need to get the Class object and we do so by calling ‘Person.class’. Once we have the Class object we can use it to call the getDeclaredMethods() method which will return an array of type Method.
To find out the names of the methods that the Person class contains we simply loop through the array and call getName() for each Method object.

If you run the example code above the output will be:







Search for more Java info on this site here:
Custom Search


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">