This question already has an answer here:
i want to iterate over methods in the order as written in the class
for example if this is the class's methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
i want to retrieve
-getName
-setName
-getId
-setId
this retrieve them randomly
Method[] methods = i.getClass().getDeclaredMethods();
for (Method method : methods) {
System.out.println(method.getName());
}
Aucun commentaire:
Enregistrer un commentaire