private ResourceAssembler<? extends BasedEntity> resourceAssembler;
List<? extends BasedEntity> bases = userRepository.findAll();
return resourceAssembler.toResources(bases, User.class); //<-----compile error
编译错误
Wrong 1st argument type. Found: 'java.util.List<? extends BasedEntity>', required: 'java.util.List<? extends BasedEntity>'
方法签名
public class ResourceAssembler<T extends BasedEntity> {
public Resources<Resource<T>> toResources(List<T> list, Class entityClass) {}
}
这是怎么回事?
可以复制并粘贴到空项目中的最小代码示例。
class Main {
ResourceAssembler<? extends BasedEntity> resourceAssembler;
List<? extends BasedEntity> bases;
void test() {
resourceAssembler.toResources(bases);
// the error is here: ^~~~~
}
}
class BasedEntity {}
class ResourceAssembler<T extends BasedEntity> {
void toResources(List<T> list) {}
}