报错内容为:
Main.java:2: error: man is not abstract and does not override abstract method compareTo(man) in Comparable
class man implements Comparable<man>{
^
1 error
我搜了很多相关的内容,也做了相应修改,不过没有解决问题
代码如下:
import java.util.Arrays;
class man implements Comparable<man>{
private int id;
private String name;
public man(int id,String name){
this.id=id;
this.name=name;
}
public String toString(){
return name;
}
@Override
public int ComparaTo(man o){
if(this.id<o.id){
return -1;
}
if(this.id>o.id){
return 1;
}
return 0;
}
}
public class testcomparable{
public static void main(String[] args) {
man mans[]={new man(45,"fcd"),
new man(55,"dcd"),
new man(15,"fcd"),
new man(85,"tcd")};
Arrays.sort(mans);
for(man s:mans)
{
System.out.println(s);
}
}
}