For fun I'm creating a sorting framework to better understand the various sorting algorithms. And, I'm trying to make it generic enough so that it can sort anything that implements an interface that extends the comparable interface. However, the java compiler isn't happy with me.
Here's my interface:
public interface Sorter<C extends Comparable<C>>
{
void sort(C[] comparables);
void sort(C[] comparables, Comparator<C> comparator);
}
And, here's my abstract class that implements that interface:
public abstract class AbstractSort<C extends Comparable<C>> implements Sorter
{
protected abstract void doSort(C[] comparables, Comparator<C> comparator);
final public void sort(C[] comparables)
{
sort(comparables, new Comparator<C>()
{
public int compare(C left, C right)
{
return left.compareTo(right);
}
});
}
final public void sort(C[] comparables, Comparator<C> comparator)
{
doSort(comparables, comparator);
}
}
And, here are the errors I'm getting:
java: name clash: sort(C[]) in AbstractSort and sort(java.lang.Comparable[]) in Sorter have the same erasure, yet neither overrides the other
Error:(25, 23) java: name clash: sort(C[],java.util.Comparator<C>) in AbstractSort and sort(java.lang.Comparable[],java.util.Comparator<java.lang.Comparable>) in Sorter have the same erasure, yet neither overrides the other
Thanks in advance for your help!