How come generic type parameter says "extends" Comparable not "implements"?

If You want to use the thing that implements You just write is as generic parameter

class Bar extends  Foo<String> { /* Code */}

The wildcard that You are talking about are three

  1. "? extends Type": Denotes a family of subtypes of type Type. This is the most useful wildcard
  2. "? super Type": Denotes a family of supertypes of type Type
  3. "?": Denotes the set of all types or any

You method should look like

public static <T extends Comparable<? super T>> Collection<T> sort(T[] list) {

        Collection<T> list = new ArrayList<T>();

         //do quicksort
        Arrays.sort(arr);

        Collection<T> list = new ArrayList<T>();
        int i;
        for(i=0; i<arr.length-1; i++) {
            if(arr[i].compareTo(arr[i+1]) != 0) { //if not duplicate, add to the list
                list.add(arr[i]);
            }
        }
        list.add(arr[i]); //add last element
//btw how do You know that last is not duplicate 
        return list;

}

For detail please visit this page


This is just the convention chosen for generics. When using bounded type parameters you use extends (even though it might mean implements in some cases) or super.

You can even do something like <E extends Comparable<E> & Cloneable> to define that the object that would replace the type parameter should implement both those interfaces.