public class Lot implements Listable {
int EmpID;
String Ename;
double Sal;
public Lot(int id,String ename, double sal) {
this.EmpID = id;
this.Ename = ename;
this.Sal = sal;
}
public int getEmpID() {
return EmpID;
}
public String getEname() {
return Ename;
}
public double getSal() {
return Sal;
}
public String toString() {
return "ID - " + EmpID + "\n" + "Name - " + Ename + "\n" + "Salary - " + Sal;
}
@Override
public int compareTo(Listable otherList) {
Lot other = (Lot)otherList;
return (this.EmpID - other.EmpID);
}
}
Main Class :
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SortTest {
public static void main(String[] args) {
List list = new ArrayList();
list.add(new Lot(4, "aaa", 12000));
list.add(new Lot(3, "bbb", 1000));
list.add(new Lot(1, "ccc", 8000));
list.add(new Lot(2, "ddd", 2500));
Collections.sort(list); //ERROR
}
}
This gives an Error 'Lot cannot be cast to java.lang.Comparable'
What is the mistake...