I hava a POJO class which has a lot of getters. Now I’m using the class Method
from the java.lang.reflect package to get all the get methods from that class. I want to invoke those getters but I don’t have idea how. ArraylistFilter
is an Arraylist<pojo>
that contains the result from my request. Option
is an Object Field data type which is the one that actually has like 100 getters. How can I get each of them without needed to call 1 by 1. what goes in my .??? there is where I want to be able to invoke my getters.
try {
Class<? extends Options> testObject = new Options().getClass();
Method[] methods = testObject.getMethods();
for (Method method : methods) {
String name = method.getName();
if (method.getName().startsWith("get") && method.getGenericParameterTypes().length == 0) {
for (int i = 0; i < ArrayListFilter.size(); i++) {
ArrayListFilter.get(i).getOptions().???;
}
}
}
} catch (Exception e) {
}
Aucun commentaire:
Enregistrer un commentaire