我想获得 Foo< T >.class 的类(正是 Foo < T>,既不是 T.class 也不是 Foo.class)
public class A extends B<C<D>>{
public A() {
super(C<D>.class); // not work
}
}
在 StackOverflow 上有一条通过注入构造函数来获取泛型类的指令,但这不是我的情况,因为 C< D>.class (eg List< String>.class) 是语法错误。在这里,它似乎与语法而不是代码结构有关。
为了显示更详细、更高级别的视图,原始代码如下,它在 Spring 框架中的 HATEOAS 模块:
public class CustomerGroupResourceAssembler extends ResourceAssemblerSupport<CustomerGroup, CustomerGroupResource>{
public CustomerGroupResourceAssembler() {
super(CustomerGroupController.class, CustomerGroupResource.class);
}
}
public class CustomerGroupResource extends ResourceSupport {
private CustomerGroup data;
}
但现在我想将 CustomerGroupResource 参数化为
public class Resource<T> extends ResourceSupport {
private T data;
}
然后
public class CustomerGroupResourceAssembler extends ResourceAssemblerSupport<CustomerGroup, Resource<CustomerGroup>>{
public CustomerGroupResourceAssembler() {
super(CustomerGroupController.class, Resource<CustomerGroup>.class); // not work here, even Resource.class
}
}
慕沐林林
相关分类