我在线程“main”java.lang.ClassCastException 中收到错误异常:com.genous.Employee 无法转换为 java.lang.Comparable
在 java.util.Arrays.mergeSort(Arrays.java:1157)
在 java.util.Arrays.sort(Arrays.java:1092)
在 java.util.Collections.sort(Collections.java:134)
在 com.genious.Employee.main(Employee.java:54)//
public class Employee implements Comparator
{
String firstname;
String lastname;
int mobileno;
public Employee(String firstname,String lastname,int mobileno)
{
this.firstname=firstname;
this.lastname=lastname;
this.mobileno=mobileno;
}
@Override
public String toString() {
return firstname;
}
@Override
public int compare(Object o1, Object o2) {
Employee e2=(Employee)o1;
Employee e3=(Employee)o2;
int i=e2.firstname.compareTo(e3.firstname);
if(i!=0)
return i;
return i;
}
/**
* @param args
*/
public static void main(String[] args) {
ArrayList list=new ArrayList();
Employee e=new Employee("anand","pandey",93456666);
Employee e1=new Employee("sheel","nidhi",678956344);
Employee e5=new Employee("shumit", "Kumar", 97390267);
Employee e6=new Employee("Kamal", "Kumar", 97390267);
list.add(e);
list.add(e1);
list.add(e5);
list.add(e6);
System.out.println(list);
Collections.sort(list);
System.out.println(list);
}
}