The sort methods for collections specifies that the parameter must be a collection of objects that implement Comparable for their own class or superclass, eg
public static <T extends Comparable<? super T>> void sort(List<T> list)
Can anyone tell me how to define an ArrayList that will only accept such objects?
I want to say
ArrayList<T extends Comparable<? super T>> eg = new ArrayList<String>();
But that doesn't compile. I could use
ArrayList<? extends Comparable<?>> ok = new ArrayList<String>();
but that's a bit too general (although the exceptions would be weird anyway).
I know I'm going to look silly when someone points out the obvious answer, but please do it anyway.
Thanks
J