Retrieving the type of a Collection
- by nevets1219
So I have something like the following in Java:
private List<SomeType>variable;
// ....variable is instantiated as so ...
variable = new ArrayList<SomeType>();
// there's also a getter
public List<SomeType> getVariable() { /* code */ }
What I would like to be able to do is figure out that variable is a collection of SomeType programmatically. I read here that I can determine that from the method getVariable() but is there any way to tell directly from variable?
I have been able to retrieve SomeType from the getter method based on the information in the link. I have also been successful in retrieving all the fields of the surrounding class via SurroundingClass.getClass().getDeclaredFields() but this doesn't tell me that it is List<SomeType>.