Hi, I have a question about generics.
I have a function that knows about a class type of object that I want to create:
public static <T> XmlParserInterface<T> createXmlParser(Class<T> rootType, String currentTagName) {
XmlParserInterface<T> result = null;
if (rootType.equals(List.class)) {
result = new XmlParserList<T>();
}
// ...
result.init(rootType, currentTagName);
return result;
}
In that function, for this special case, I call it with rootType being List<String>.
In my init function, I pass again the rootType so that I can create an ArrayList<something>. My problem here is to find the something since I will need it to generate further objects. In this case, it would be String, but it could go even deeper with being a List<List<String>> or even a custom POJO that I check for their set functions to fill them.
I tried doing rootType.getTypeParameters()[0], but it only returns me E. I need to know the actual class of the E.
Thanks if anyone can answer that :)