Reputation: 14439
How can I set generic type? For example:
Class<List<Integer>> asd = List<Integer>.class \\ does not work
May be that is a bit stupid question, but I have never met a code where this thing was done.
Upvotes: 5
Views: 2894
Reputation: 13914
In short, what you want is List.class
; the generic types are only available at compile-time, and are "erased" at run-time. There's a brief explanation here: http://docs.oracle.com/javase/tutorial/java/generics/erasure.html
...and a bit more detail here: http://www.artima.com/weblogs/viewpost.jsp?thread=208860
Upvotes: 3
Reputation: 38526
This is not possible, due to type erasure. There's a number of hacks in various libraries to help out with reflection, but the language itself has generally poor support for introspection of generic types.
Upvotes: 2