I've done a lot of searching through generic type questions and just haven't found anything that has helped me figure out what I am doing wrong here. I have an interface as follows:
public interface SortAnalysis<E extends Comparable<? super E>>
{
public long analyzeSort(ArrayList<E> list);
}
Now, the next step is making a class that implements this interface. This particular class is going to use an insertion sort and I need to keep the ArrayList type 'E' generic, so I tried all sorts of things and ended up with the following:
public class InsertionSort<E extends Comparable<? super E>> implements SortAnalysis {
@Override
public long analyzeSort(ArrayList list) {
// TODO Auto-generated method stub
return 0;
}
My problem is that when I try to do this for the parameter
ArrayList<E> list
the compiler gripes at me about implementing a supertype method.
I would really appreciate any direction of help. Thanks!
**I can't mark this as answered yet, but it is. I think my problem had been that when I had
SortAnalysis<E>
I did not have the generic typing listed after the class name.**
Specify the type like SortAnalysis<E>
in
public class InsertionSort<E extends Comparable<? super E>>
implements SortAnalysis<E> {
when you omit it you have a raw-type and not a generic version.
When declaring your InsertionSort
class, you are implementing the raw form of the SortAnalysis
class. That means that analyzeSort
isn't properly overriding SortAnalysis
when you include <E>
on the list
parameter.
Supply a type parameter in the implements
clause.
class InsertionSort<E extends Comparable<? super E>>
implements SortAnalysis<E> {
// ^^^
Now you can include <E>
in the list
parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With