Reputation: 91
ArrayList<ShipDetail> detailArray = new ArrayList<ShipDetail>(Arrays.asList(shipDetail));
Sorter.QuickSort( detailArray );
And this is my Sorter class in which I was trying to do Implement some algorithms.
public class Sorter
{
public static<T extends Comparable<T>> void QuickSort(AbstractList<T> collection )
{
quickSort(collection,0,collection.size()-1);
}
}
But while compiling i am getting the following error :
required: AbstractList found: ArrayList reason: inference variable T has incompatible bounds equality constraints: ShipDetail upper bounds: Comparable where T is a type-variable: T extends Comparable declared in method QuickSort(AbstractList)
Upvotes: 2
Views: 6167
Reputation: 1654
ShipDetail
is not comparable to itself. The bound here:
<T extends Comparable<T>>
Also applies to the type variable T
in the argument, which is inferred as ShipDetail
.
ShipDetail
should be defined as follows:
class ShipDetail implements Comparable<ShipDetail> { ...
And not:
class ShipDetail implements Comparator<ShipDetail> { ...
Comparator
s are objects-algorithms which provide service of comparison of other objects, while Comparable
s are objects which themselves allow comparing them to other kind of objects.
Upvotes: 6