I'm using reflection to walk the field members of a class and I need to know for List<> subclasses, what the generic type parameters are.
Given a field that has a type that is a subclass of List, how can I tell in a generic way what the type parameters of List<> are?
For example:
class X<T> {
List<String> x1; // String
ArrayList<String> x2; // String
SubclassOfArrayListString x3; // String
List<?> x4; // error
List<T> x5; // error
}
class SubclassOfArrayListString extends ArrayList<String> {
// ...
}
NOTE: I added <T>
to X above to illustrate that there might be cases where there isn't a correct answer - it has nothing to do with the problem, except being something to consider when answering.