Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set generic class type

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.

like image 743
michael nesterenko Avatar asked Dec 02 '11 19:12

michael nesterenko


1 Answers

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

like image 59
BRPocock Avatar answered Sep 22 '22 05:09

BRPocock