jeudi 25 avril 2019

Check if a class is an instance of list

I need to get all methods in a class that can return a List and then, check for all those method what type of List it is.

I do:

Person person = new Person();
Class c = person.class;
for (Method m: c.getDeclaredMethods()) {
    // this gets me all the getters
    if (m.getParameterTypes().size() == 0) {
        Class<?> returnType = m.getReturnType()
        if (returnType.equals(java.util.List.class)) {
              // Can get here
              // But how to get the class that is used to parameterise the 
              // list.
        }
    }
}

How do I get the Class that is used to parameterise a List?





Aucun commentaire:

Enregistrer un commentaire