2
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)

Anmol
  • 91
  • 1
  • 3
  • 10

1 Answers1

6

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> { ...

Comparators are objects-algorithms which provide service of comparison of other objects, while Comparables are objects which themselves allow comparing them to other kind of objects.

mszymborski
  • 1,615
  • 1
  • 20
  • 28