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

Thanks, I was wrestling with this issue for about an hour until I found this. =)
Thank you.
Thanks, I miss 2 hours in this problem. You save my day.
Thanks, saved me some time
Thanks man, I couldn’t figure out what was going on for the life of me.
You saved my life. Thx
Thanks so much. That saved me a ton of time!
Is it me or a variable name is missing after your parameter type (List) ???
Same problem. 3 hours later, I found your post and that's it: You made my day!
Thank you so much, this definitely saved me a lot of time.
THANK YOU!!!
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?
Thanks for posting this. It saved me tons of trouble!
FTW!
Thanks for posting this.
Thank God
You are my hero!! I spent way too long trying to figure this one out.
thanks a bunch!
Like all the above..thanks!
thank you you saved my life
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.
Karma & kudos, saved me time & pain as well.
Thanx for the post. Google + you saved me a lot of trouble.
Generics are PITA