views:

115

answers:

1
Class c = List<Foo>.class

doesn't seem to work.

+8  A: 

There isn't one. In Java, concrete generic types have no exact runtime type representation. This is a consequence of the much-maligned type erasure. Effectively, this means that List<Foo> is the same runtime type as List<Bar>; checking whether generic operations are legal happens at compile time, not runtime. Once you're in bytecode, they're all List, so saying something like List<X>.class is nonsensical to some degree.

See this FAQ for more details.

John Feminella