我有以下课程:
public interface ModelObject {
}
public interface Resource {
}
public interface Transformer <F,T>{
}
public interface WrapperFactory {
Transformer<Resource, Wrap<? extends ModelObject>> createMapper();
}
public class Wrap<E extends ModelObject> {
}
public class AbstractBaseTransformer<F,T> implements Transformer<F,T> {
}
public class ConcreteModel implements ModelObject {
}
public class ConcreteTransformer extends AbstractBaseTransformer<Resource, Wrap<ConcreteModel>> {
}
public class ConcreteFactory implements WrapperFactory {
@Override
public Transformer<Resource, Wrap<? extends ModelObject>> createMapper() {
return new ConcreteTransformer();
}
}
ConcreteFactory 未编译,说明 ConcreteTransformer 与返回的不兼容
Transformer<Resource, Wrap<? extends ModelObject>>
我看不出这里有什么问题。ConcreteTransformer 将第一个参数绑定到 Resource(与预期相同),同时将第二个参数绑定到:
Wrap<ConcreteModel>
应该绑定到:
Wrap<? extends ModelObject>
正如 ConcreteModel 实现的那样。