尝试编译代码时出现找不到符号错误。我检查了所有标准答案,实现了一个比较器,我包含了我使用的东西,我为函数提供了正确的类型。那么我错过了什么?
这是代码:
import java.util.*;
class Planner implements MinSpanTree {
public List<Road> findCheapConversionPlan(List<Junction> junctions, List<Road> roads){
Collection.sort(roads);
return roads;
}
}
道路等级包括:
class Road implements Comparable<Road> {
@Override
public int compareTo(Road other){
double diff=this.weight-other.getWeight();
if (diff == 0) return 0;
if (diff > 0) return 1;
return -1;
}
public int compare(Road x, Road y){
double diff=x.getWeight()-y.getWeight();
if (diff == 0) return 0;
if (diff > 0) return 1;
return -1;
}
}
每次我尝试编译 Planner.java 类时,都会遇到同样的错误:
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
Planner.java:11: error: cannot find symbol
Collection.sort(roads);
^
symbol: method sort(List<Road>)
location: interface Collection
1 error
我的 javac 版本是 javac 1.7.0_79。根据oracle docs Collection.sort 至少应该从 1.6 开始实施。