Name clash: The method BLAH has the same erasure as type BLAH but does not override it
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.


on March 8th, 2007 at 11:17 am
Thanx for the post. Google + you saved me a lot of trouble.
Generics are PITA
on March 9th, 2007 at 10:44 am
Karma & kudos, saved me time & pain as well.
on March 26th, 2007 at 1:37 am
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.
on April 5th, 2007 at 8:14 pm
thank you you saved my life
on April 11th, 2007 at 4:15 pm
Like all the above..thanks!
on August 10th, 2007 at 12:10 pm
thanks a bunch!
on September 18th, 2007 at 10:35 am
You are my hero!! I spent way too long trying to figure this one out.
on September 23rd, 2007 at 5:51 pm
Thank God
on October 21st, 2007 at 9:53 pm
:D
on November 17th, 2007 at 11:47 am
FTW!
Thanks for posting this.
on February 27th, 2008 at 11:11 am
Thanks for posting this. It saved me tons of trouble!
on April 2nd, 2008 at 5:38 am
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?
on July 26th, 2008 at 6:15 am
THANK YOU!!!