我正在嘗試使用Collections.sort()對List<Point2D>
點進行排序。我相信我正確設置了這個比較器。無論如何,這是拋出一個錯誤說:The method sort(List<T>, Comparator<? superT>) in the type Collections is not applicable for the arguments (List<Point2D>, new Comparator<Point2D.Double>(){})
。有人明白我的編譯器爲什麼會拋出這個錯誤嗎?Point2D比較器拋出錯誤
Collections.sort(points, new Comparator<Point2D.Double>() {
public int compare(Point2D.Double p1, Point2D.Double p2) {
return Double.compare(p1.getX(), p2.getX());
}
});
如果你有Point2D'的'名單,那麼你需要'Point2D'比較。目前你有一個'Point2D.Double'的比較器,它是不一樣的。 – Turamarth