[英]What is the Class Of List<Foo> in Java?
Class c = List<Foo>.class
似乎不起作用。
There isn't one. 没有一个。 In Java, concrete generic types have no exact runtime type representation.
在Java中,具体的泛型类型没有确切的运行时类型表示形式。 This is a consequence of the much-maligned type erasure .
这是种类繁多的类型擦除的结果 。 Effectively, this means that
List<Foo>
is the same runtime type as List<Bar>
; 实际上,这意味着
List<Foo>
与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. 一旦使用字节码,它们全都是
List
,因此说诸如List<X>.class
东西在某种程度上是荒谬的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.