Kind of new to working with generic classes but I'm trying to make a simple sorting algorithm but I can't get past this one problem for the life of me and I just know it's gotta be some really small and simple mistake I can't figure out.
public class InsertionSort<T extends Comparable<T>> implements Sorter<T>
{
ListInterface<T> list;
public void sort(ListInterface<T> list) {
this.list = list;
if(list.get(key).compareTo(list.get(key-1)) > 0) {}
//ERROR
}
}
My Sorter interface extends Comparable too...
public interface Sorter<T extends Comparable<T>> {
public void sort(ListInterface<T> list);
}
My ListInterface is an interface for ArrayLists and LinkedLists, all generic type T but they do not extend Comparable, and they shouldn't! They're lists and you can insert any object into them even if they are not Comparable. I'm really not sure why I'm getting this compilation error.