Elliott C. Back: Internet & Technology

Name clash: The method BLAH has the same erasure as type BLAH but does not override it

Posted in Java by Elliott Back on December 24th, 2006.

I was getting the following error in Eclipse IDE 3.1 and Java 1.5 (or 5.0 as some like to call it):

Name clash: The method removeEldestEntry(Map.Entry<K ,V>) of type LRUMap<K ,V> has the
same erasure as removeEldestEntry(Map.Entry<K , V>) of type LinkedHashMap<K , V> but does not
override it

The class in question looked like this:

class LRUMap <K , V> extends LinkedHashMap {
	public LRUMap(){
		super(10000, .75f, true);
	}

	protected boolean removeEldestEntry (Entry <K , V> eldest) {
		return this.size() > 262144;
	}
}

The problem is that I was extending LinkedHashMap without type parameters, not LinkedHashMap >K ,V<. Changing the code to:

class LRUMap <K , V> extends LinkedHashMap <K , V> {
	public LRUMap(){
		super(10000, .75f, true);
	}

	protected boolean removeEldestEntry (Entry <K , V> eldest) {
		return this.size() > 262144;
	}
}

completely fixed the problem! Type erasure is sure a pain, no? I should probably spend more time at home reading the Java Generics Tutorial.

This entry was posted on Sunday, December 24th, 2006 at 11:27 am and is tagged with eclipse ide, type parameters, java generics, time at home, boolean, blah, clash, lt, erasure, map. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback.

20 Responses to “Name clash: The method BLAH has the same erasure as type BLAH but does not override it”

  1. al_shopov says:

    Thanx for the post. Google + you saved me a lot of trouble.
    Generics are PITA

  2. mrh says:

    Karma & kudos, saved me time & pain as well.

  3. sammy says:

    Wow. i spend 30 minutes staring at 20 lines of code trying to figure it out before finally swallowing my pride and googling the problem. and this hit the nail on the head.

  4. miss acacia says:

    thank you you saved my life

  5. KC says:

    Like all the above..thanks!

  6. rmn says:

    thanks a bunch! :)

  7. DRJ says:

    You are my hero!! I spent way too long trying to figure this one out.

  8. Jake says:

    Thank God

  9. Julius says:

    FTW!

    Thanks for posting this. :)

  10. Emily says:

    Thanks for posting this. It saved me tons of trouble!

  11. h0le says:

    Hi,

    Unfortunately, I still have a problem.

    I get the error if I try to override the following:

    abstract String method(List s);

    with:

    @Override
    public String method(List) {
    }

    :(

    Where is the error?

  12. johnLasta says:

    THANK YOU!!!

  13. Zurch says:

    Thank you so much, this definitely saved me a lot of time.

  14. aki says:

    Same problem. 3 hours later, I found your post and that's it: You made my day!

  15. aki says:

    Is it me or a variable name is missing after your parameter type (List) ???

  16. James says:

    Thanks so much. That saved me a ton of time!

  17. alberto says:

    You saved my life. Thx

  18. Charlie says:

    Thanks man, I couldn’t figure out what was going on for the life of me.

  19. Marauder says:

    Thanks, saved me some time :-)

Leave a Reply

Powered by WP Hashcash