I have;
List stringList = new ArrayList();
List integerList = new ArrayList();
Is
At runtime, no, you can't.
However via reflection the type parameters are accessible. Try
for(Field field : this.getDeclaredFields()) {
System.out.println(field.getGenericType())
}
The method getGenericType()
returns a Type object. In this case, it will be an instance of ParametrizedType
, which in turn has methods getRawType()
(which will contain List.class
, in this case) and getActualTypeArguments()
, which will return an array (in this case, of length one, containing either String.class
or Integer.class
).