
February 8th, 2013, 02:11 PM
|
|
Contributing User
|
|
Join Date: Feb 2011
Posts: 70
Time spent in forums: 12 h 17 m 16 sec
Reputation Power: 3
|
|
|
Homework - Trouble with inheritance + methods that take in generics
I'm having problems overriding a method from an interface that takes in a generic type.
The code from my interface looks like this:
public interface KDTree<E extends Location> {
...
void insert(E element);
...
}
And for the class:
public class BulkInsertKDTree<E extends Location>
implements KDTree, Iterable {
...
@Override
public void insert(E element) {
//Code
}
...
}
The compiler gives me 2 different errors:
error: BulkInsertKDTree is not abstract and does not override abstract method insert(Location) in KDTree
error: name clash: insert(E#1) in BulkInsertKDTree and insert(E#2) in KDTree have the same erasure, yet neither overrides the other
It seems like the compiler isn't equating the second insert with the first because each one takes in a generic type, and java doesn't recognize that the two are treated the same way. Is there any way I can fix this?
Thanks!
|