Consider the code:
public abstract class Item implements Comparable
{
protected T item;
public int compareTo(T o)
{
re
Actually more detailed explanation of this error gives your javac itself:
java: no suitable method found for
sort(java.util.ArrayList)> method
java.util.Collections.is not applicable (cannot instantiate from arguments because actual and formal argument lists differ in length)sort(java.util.List ,java.util.Comparator super T>) method
java.util.Collections.is not applicable (inferred type does not conform to declared bound(s) inferred:sort(java.util.List ) MyItembound(s):java.lang.Comparable super MyItem)>
So, the main question is:
why is method Collections.) not applicable?
The answer is:
because in Collections. method declaration there are bounds on parameter T: .
In another words, T must implement Comparable interface on it self. For example String class implements such interface: ...implements ... Comparable.
In your case Item class doesn't implement such interface:
Item is not same thing as Item.
So, for solving this problem, your should change your Item class to this one:
public abstract class Item implements Comparable- >
{
protected T item;
public int compareTo(Item
o)
{
return 0; // this doesn't matter for the time being
}
}