开发者

Create java Parameterized Type on the fly

开发者 https://www.devze.com 2023-03-08 20:54 出处:网络
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 ty

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消