進行參數作爲Java中的初學者,我得到以下編譯錯誤嘗試自定義比較分配給一組:設置比較器不是通用的;它不能與參數
The type mycode.pointComparator is not generic; it cannot be parameterized with arguments
這裏是我的代碼:
Set<Point3d> cornerPoints = new TreeSet<Point3d>(new pointComparator<Point3d>());
class pointComparator implements Comparator<Point3d> {
@Override
public int compare(Point3d o1, Point3d o2) {
if(!o1.equals(o2)){
return -1;
}
return 0;
}
}
我進口Java.util.
包
更新: 刪除此錯誤<Point3d>
參數結果:
No enclosing instance of type mycode is accessible. Must qualify the allocation with an enclosing instance of type mycode (e.g. x.new A() where x is an instance of mycode).
讓我們來看看...'類型mycode.pointComparator不是通用的;它不能用參數'參數化。只有一種方法來閱讀此。 –
從'new point'中刪除''比較者()'... –
assylias