如何获得generics定义实体的.class?

那么如何在Java中执行以下操作?

List strings = new ArrayList(); JAXBElement<List> jax = new JAXBElement<List>(new QName("strings"), List.class, strings); 

该问题特别发生在List.class,返回的错误是:

 Multiple markers at this line - List cannot be resolved to a variable - String cannot be resolved to a variable - Syntax error on token ">", void expected after this token 

你不能。

与您想要的最接近的是使用(Class>) List.class

这是因为没有List.class ,因为在运行时, ListListListList在Java中都是相同的。 这是故意为一大堆原因而做的,它被称为类型擦除。