Possible duplicates:
Java Reflection: getting fields and methods in the order of Java declaration
. Get declared methods so that they appear in the source code
Suppose I have this class
Is it possible to use getter methods?
public class ClassA {
private String name;
private Integer number;
private Boolean bool;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public Boolean getBool() {
return bool;
}
public void setBool(Boolean bool) {
this.bool = bool;
}
}
I have tried this.
for (Method method : ClassA.class.getDeclaredMethods()) {
if (!(method.getReturnType().toString().equals("void"))) {
method.invoke(obj, new Object[0])));
}
}
I got this from the documentation
... Elements of the returned array are not sorted and are not in a specific order ...
So ... is it easy? Is there some kind of alternative, or do I just need to implement something?
source
share