I am getting compilation error:Bound mismatch: The generic method sort(List<T> ) of type Collections is not applicable for the arguments (ArrayList<Dvd> ) . The inferred type Dvd is not a valid substitute for the bounded parameter <T extends Comparable<? super T>> at Generics1.main.
can anyone explain what Comparable<? super T> means Thanks Raj [ May 29, 2007: Message edited by: raj malhotra ]
Your DVD class must implement Comparable interface so that sort() method could sort the object of DVD whose references are staying in the ArrayList.
Joined: Feb 28, 2007
can anyone explain what Comparable<? super T> means
In simple wordings it does mean that it is not must that class T implements the Comparable interface. If super class of that implements the Comparable it will also do.
In your case you experiment with what I say:
1- First try by making your Dvd class implement Comparable interface. 2- After that you make a new class and extend the Dvd class from that. Parent class of Dvd class should implement the Comparable this time so that you could test the meaning of Comparable<? super T>
Following on from what Chandra wrote: class Dvd can implement interface Comparable<Dvd> simply by having a suitable int compareTo(Dvd dvd) method defined. [ May 29, 2007: Message edited by: Barry Gaunt ]
Got it.Any class ,which implements Comparable interface or whose super class implements it,can be used to sort using Collections.sort(T o) Thanks Chandra & Barry [ May 29, 2007: Message edited by: raj malhotra ]