I want to know if I can get the methods that returns class members.
For example I have a class called Person
inside this class there is two members that are name
and age
and inside this class I have 4 methods as follow :
public class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
so if I use the method Person.class.getDeclaredMethods();
it returns all the methods that are declared inside this class and also Person.class.getDeclaredMethods()[0].getReturnType();
returns the return type of the method.
But what I need is to get the methods that returns the two variables name
and age
In this case the methods are public String getName()
and public int getAge()
.
What can I do?