鉴于这个原型:
public static <C extends SetComposite, S extends Iterable<U>, U> boolean
eligibleForInclusion(C me, Class<C> clazz, List<S> members) throws TypeCollisionException {
...
}
这个电话网站:
public void include(RestaurantSet member) {
if (SetCompositeUtils.<RestaurantSetComposite, RestaurantSet, Restaurant>
eligibleForInclusion(this, this.getClass(), Arrays.asList(member))) {
inc.add(member);
}
}
Eclipse编译器给出了这个错误:
The parameterized method <RestaurantSetComposite, RestaurantSet, Restaurant>eligibleForInclusion(RestaurantSetComposite, Class<RestaurantSetComposite>, List<RestaurantSet>) of type SetCompositeUtils is not applicable for the arguments (RestaurantSetComposite, Class<capture#1-of ? extends RestaurantSetComposite>, List<RestaurantSet>)
如果我正确阅读,则Class<capture#1-of ? extends RestaurantSetComposite>
与Class<RestaurantSetComposite>
不匹配。我可以以某种方式解决这个问题吗?
答案 0 :(得分:2)
由于您的this
可能是子类的实例,this.getClass()
可能不完全是RestaurantSetComposite.class
,因此您需要
public static <C extends SetComposite, S extends Iterable<U>, U> boolean
eligibleForInclusion(C me, Class<? extends C> clazz, List<S> members) throws TypeCollisionException {
...
}