我试图使用Collections.sort自定义对象的ArrayList的,但我得到一个警告,我想不通为什么Java的警告与实施可比
Warning: Type safety: Unchecked invocation
sort(ArrayList<CharProfile>) of the generic method sort(List<T>)
of type Collections
有了这个代码:
ArrayList<CharProfile> charOccurrences = new ArrayList<CharProfile>();
...
Collections.sort(charOccurrences);
这是我的方法:
public class CharProfile implements Comparable {
...
@Override
public int compareTo(Object o) {
if (this.probability == ((CharProfile)o).getProbability()) {
return 0;
}
else if (this.probability > ((CharProfile)o).getProbability()) {
return 1;
}
else {
return -1;
}
}
}
什么是“其他”的“的compareTo()”方法开始在做什么? –