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