[英]Incompatible Types when when using a list of generic class in an interface
I'm using java 1.8 and I get this incompatibility error.我正在使用 java 1.8 并收到此不兼容错误。
public interface AVCR<T extends ACRI> {
List<CRTIL<T>> getLists();
}
public class CRTIL<T extends ACRI> {
}
class BV {
public AVCR<? extends ACRI> getDeafult() {
return;
}
public List<CRTIL<? extends ACRI>>
getTypeLists() {
return getDefault().getLists();
//Incompatible types
}
}
The compiler error: found编译器错误:发现
List<? extends CRTIL<? extends ACRI>>
and requires并要求
List<CRTIL<? extends ACRI>>
I am not sure if I understand your question correctly as you do not provide a minimal working example but I try:我不确定我是否正确理解了您的问题,因为您没有提供最小的工作示例,但我尝试:
You could change the method signature of getTypeLists
as follows您可以按如下方式更改
getTypeLists
的方法签名
public List<? extends CRTIL<? extends ACRI>> getTypeLists()
since you are returning a list of type ? extends CRTIL<? extends ACRI>
因为您要返回类型列表
? extends CRTIL<? extends ACRI>
? extends CRTIL<? extends ACRI>
? extends CRTIL<? extends ACRI>
and not of type CRTIL<? extends ACRI>
? extends CRTIL<? extends ACRI>
而不是CRTIL<? extends ACRI>
CRTIL<? extends ACRI>
. CRTIL<? extends ACRI>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.