I have a quite hard time to get my code running. I have a generic method, that should sort and remove all duplicates from a given List. The items in the List, for example, String, all implement the Comparable interface. Unfortunately, the code is not compiling and I don't understand why...
public static <T> List<T> distinctAndSort(List<T> s) {
List<T> list = s.stream().distinct().collect(Collectors.toList());
Collections.sort(list); //Error
return list;
}
This is what I got so far. Why can't I put my List<T> into sort? (The method sort(List<T extends Comparable<? super T>>) in the type Collections is not applicable to the arguments (List<T>).
In order to make my function work, what am I missing? Thx for every help