Help with interface implementation. Suppose we have an interface
public interface Sorter<T extends Comparable<T>> { void sort(List<T> list); }
and I want to create a class that will implement this interface using genec types. I tried this:
public class SorterImpl<T extends Comparable<T>> implements Sorter<T > { public void sort(List<T> list){ boolean erijuht1 = true; boolean erijuht2 = true; for(int a=0; a<list.size()-1; a++){ if(list.get(a) > list.get(a+1)){ erijuht1 = false; } if(list.get(a) < list.get(a+1)){ erijuht2 = false; } } } }
The problem is that the last class does not want to compare objects with each other. How can I implement this interface in such a way that the class is with a generic type and can compare objects?