avadha
avadha

Reputation: 9

how to get a list of methods from a class in java?

I want to enter the path of the java class as input and in output it should give me the list of methods in that class.how do i proceed ? can anyone guide me.pls.

Upvotes: 0

Views: 225

Answers (4)

Punam
Punam

Reputation: 48

You can give the path name in double quotation and get the java class.From the java class you can get array of methods, and by iteration over the array of methods you can name of the methods by its .getName() method, and it can be converted to list.

Class class = Class.forName("com.nextenders.facadeimplementation.facade."
                    + className);
    Method[] mymethods = class.getMethods();

let me know if it works or not

Thanks, Punam

Upvotes: 1

AlexR
AlexR

Reputation: 115338

You can do it programmatically using reflection API (obj.getClass().getDeclaredMethods()) or using command line utility javap that is a part of your JDK distribution.

Upvotes: 0

Rocky
Rocky

Reputation: 951

You can use Java Reflection API - To find out about how to use it go through http://docs.oracle.com/javase/tutorial/reflect/class/classMembers.html

Upvotes: 1

Sunil Kumar B M
Sunil Kumar B M

Reputation: 2795

Class personClass = Person.class;

//Get the methods
Method[] methods = personClass.getDeclaredMethods();

//Loop through the methods and print out their names
for (Method method : methods)
{
    System.out.println(method.getName());
}

Upvotes: 1

Related Questions