2
我有这个接口Java集合比较扩展,扩展接口相当的通用类
public interface IDataPoint<T> extends Comparable<T> {
public T getValue();
}
实施这一项目...
public class IntegerDataPoint implements IDataPoint<Integer> {
// ... some code omitted for this example
public int compareTo(Integer another) {
// ... some code
}
}
和其他类...
public class HeatMap<X extends IDataPoint<?> {
private List<X> xPoints;
}
现在我想在xPoints
列表上使用Collections.max(和类似的),但这不起作用,可能是因为我把我的泛型全搞糟了。
任何建议如何解决这个问题(没有Comparator
)?
Collections.max(xPoints);
给了我这个错误:
Bound mismatch: The generic method max(Collection<? extends T>) of type Collections is not applicable for the arguments (List<X>). The inferred type X is not a valid substitute for the bounded parameter <T extends Object & Comparable<? super T>>
你的意思是'不起作用'是什么意思?你的compareTo没有被调用? – 2012-04-18 14:14:20
请定义“不起作用”。 – Vincent 2012-04-18 14:16:16
增加了一些细节... – Mickel 2012-04-18 14:17:00