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.

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

  1. Erica says:

    Thanks, I was wrestling with this issue for about an hour until I found this. =)

  2. Frank says:

    Thank you.

  3. Marcelo Estrela says:

    Thanks, I miss 2 hours in this problem. You save my day.

  4. Marauder says:

    Thanks, saved me some time :-)

  5. Charlie says:

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

  6. alberto says:

    You saved my life. Thx

  7. James says:

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

  8. aki says:

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

  9. aki says:

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

  10. Zurch says:

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

  11. johnLasta says:

    THANK YOU!!!

  12. 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?

  13. Emily says:

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

  14. Julius says:

    FTW!

    Thanks for posting this. :)

  15. Jake says:

    Thank God

  16. DRJ says:

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

  17. rmn says:

    thanks a bunch! :)

  18. KC says:

    Like all the above..thanks!

  19. miss acacia says:

    thank you you saved my life

  20. 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.

  21. mrh says:

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

  22. al_shopov says:

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

Leave a Reply

Powered by WP Hashcash