Tag: nested generics

Java中的嵌套类型参数

这是一个我编写的实例代码的简化示例,所以如果它有点人为,我会道歉。 我想要做的是从单个嵌套类型参数中有效地获取两个类型参数。 我很确定这是不可能的,但我想我会试一试。 //Not legal java code public class Foo<C extends Collection> { //where T is another type parameter private C coll; public Foo(C coll) { this.coll = coll; } public void add(T elem){ this.coll.add(elem); } //UPDATED TO ADD GETTER /** * I may need to retrieve the collection again, or pass it * on […]

如何获得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