Create java Parameterized Type on the fly
How to create a java.lang.reflect.Type
of type List<T>
on the fly if I know T开发者_StackOverflow
is of certain type like String.class
or Integer.class
?
Java parameterized types are subject to type erasure so that generic types are lost at runtime. This means that, at runtime, a List<String>
is indistinguishable from a List<Integer>
or a List<Object>
, without inspecting the elements in the list.
All this to say, you don't need to worry about the parameterized type at all. You can just create a List
.
精彩评论