#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    70
    Rep Power
    4

    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!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    74
    Rep Power
    19
    Just a wild guess, but in the interface the method is declared private, while in the implementing class it is declared as public. What happens if you make the access levels equal?

IMN logo majestic logo threadwatch logo seochat tools logo