Collection.sort: 'cannot find symbol' 尽管给出了正确的类型,包括比较器

Collection.sort: 'cannot find symbol' despite giving right type, include, comperator

我在尝试编译代码时遇到找不到符号错误。 我检查了所有的标准答案,有一个实现的比较器,我包括了我使用的东西,我给了函数正确的类型。 那我错过了什么?

代码如下:

import java.util.*;
class Planner implements MinSpanTree {

public List<Road> findCheapConversionPlan(List<Junction> junctions, List<Road> roads){
    Collection.sort(roads);
    return roads;
}
}

道路class包括这条:

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 class,我都会得到同样的错误:

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。 根据 the oracle docs Collection.sort 应该至少从 1.6 开始实施。

您错过了 Collection 接口的辅助方法 Collections 中的 s

Collections.sort

您引用的 link 属于 Collections class。不是 Collection