I'm trying to understand the name clash error I get with the following code:
import java.util.*;
import javax.swing.*;
class Foo<R extends Number> {
public void doSomething(Number n, Map<String, JComponent> comps) {
}
}
class Bar extends Foo {
public void doSomething(Number n, Map<String, JComponent> comps) {
}
}
Error message:
error: name clash:
doSomething(Number,Map<String,JComponent>)
inBar
anddoSomething(Number,Map<String,JComponent>)
inFoo
have the same erasure, yet neither overrides the other
I know I can fix it by either remove the generic type from Foo
, or by changing the Bar
declaration to class Bar extends Foo<Integer>
; what I want to know is why this error occurs in the specific case, but goes away if I remove the comps
parameter from each method. I've done some reading about type erasure, but it still appears to me that both methods should have the same erasure with or without generics, and therefore be a valid override in either case. (Note that I haven't even used the generic parameter anywhere yet, which is why I'm so surprised.)
I know that I've added generic types to parent classes before but only got warnings about the subclasses, not errors. Can anyone explain this scenario?
Foo
. – Crispatecomps
arguments from both. Possibly something to do with bridge methods, but I can't see it. – FlavescentMap
interface use generics, and maybe that's why it's complaining. Which specific version of Java are you using? By specific, I mean java 6 u30, for example, or Java 7 u40. – CrispateMap
; not sure what that tells us. – Flavescentjavac
is giving me the same results – Flavescent