【发布时间】:2018-01-02 14:48:53
【问题描述】:
我一直在写我的期末论文,构建一个 Java 程序来实现 K-means 算法,但我遇到了这个错误:
对象无法转换为点。
这是我的错误所在的代码
public void plotCluster() {
System.out.println("[Cluster: " + id+"]");
System.out.println("[Centroid: " + centroid + "]");
System.out.println("[Points: \n");
for(Point p : points) { // error
System.out.println(p);
}
System.out.println("]");
}
【问题讨论】:
-
你声明列表时是否带有类型参数
<>?喜欢List<Point>? -
@SuryaHandika ,请用完整的代码更新您的问题
-
List
myList = new ArrayList (); -
@Eric 是的,但只要做到
List<Point> myList = new ArrayList<>()
标签: java