I am trying to figure out what type of class a List is implementing in my program.
I am grabbing JSON data and placing it in a root object. This root object then has Lists in it to store each element of the JSON data.
For example I have a root that has a declared fields of
List<Person> people
List<Location> locations
So what I want to be able to do is loop through each field of the root class, grab the type of class the list that I am currently looking at is, and then call a specific function for that class. (when I say specific function I mean I have an interface declared such that I can just return that class type that implements the interface and run the function that it implements to take the list apart.
calling Class<?> clss = fieldObj.getType() (where fieldObj is type Field) just returns that it is a list. How do I get what type of list this field is?
If you are looking for the type of the object contained in the list at runtime, you cannot do so from the
Listitself. This is because of type erasure which means that at runtime allLists areList<Object>. If you need to determine the type of the object in the list, get the first element in the list and do aninstanceoforassignableFrom