Im trying to have an Object implement a custom Comparable but the single compareTo(T o) method found in the Comparable interface has to stay like it is. ie Having an object as a parameter. So i added in the cast to the type which is being held in the Collection and thus being sorted upon. The line i added It sounds correct since a ClassCastException should never be thrown since the Collection is marked to hold only employee objects. Any ideas? Thanks.
Code:public int compareTo(Object o){ Employee e = (Employee)o; // added line int i = lname.compareTo(e.lname); return (i != 0 ? i : fname.compareTo(e.fname)); }


Reply With Quote
