Community
Participate
Working Groups
N20050609-0010 Javac 1.5.0_03-b07 compiles this code and makes Ex#method(..) override Top#method(). Eclipse rejects the first call to ex.method(..) with this error: "The method method(Object, Object) is ambiguous for the type Ex". IMethodBinding#overrides(..) says that Ex#method(..) does not override Top#method(). public class Try { public static void main(String[] args) { Ex ex= new Ex(); ex.method("Eclipse1", new Integer(1)); Top top= ex; top.method("Eclipse2", new Integer(2)); } } class Top<TC> { <TM> void method(TC cTop, TM mTop) { System.out.println("Top"); } } class Ex<C> extends Top<C> { <M> void method(C cEx, M mEx) { System.out.println("Ex"); } } When I change Ex to ... class Ex<C extends String> extends Top<C> { <M extends Integer> void method(C cEx, M mEx) { System.out.println("Ex"); } } ... then the two compilers agree that the methods don't override and accept the program.
Changing Ex to be: class Ex<C> extends Top<C> { @Override <M> void method(C cEx, M mEx) { System.out.println("Ex"); } } is accepted by both Eclipse & javac. IMethodBinding#overrides() must have a bug if its not accepting this case.
This case works 'properly' as it reports the unchecked warning: class Try { public static void main(String[] args) { new Ex().method2(new Integer(1)); } } class Top<TC> { <TM> void method2(TM mTop) { System.out.println("Top"); } } class Ex<C> extends Top<C> { @Override <M> void method2(M mEx) { System.out.println("Ex"); } }
Here is the full case, where we currently fail the 2 messages sends with type args (all 4 should be unchecked warnings): class Try { public static void main(String[] args) { Ex ex= new Ex(); ex.method("Eclipse1", new Integer(1)); ex.method2(new Integer(1)); ex.method3(new Integer(1)); ex.method4(new Integer(1)); } } class Top<TC> { <TM> void method(TC cTop, TM mTop) { System.out.println("Top"); } <TM> void method2(TM mTop) { System.out.println("Top"); } void method3(TC cTop) { System.out.println("Top"); } <TM> void method4(TC cTop) { System.out.println("Top"); } } class Ex<C> extends Top<C> { @Override <M> void method(C cEx, M mEx) { System.out.println("Ex"); } @Override <M> void method2(M mEx) { System.out.println("Ex"); } @Override void method3(C cEx) { System.out.println("Ex"); } @Override <M> void method4(C cEx) { System.out.println("Ex"); } }
This is only a problem with Raw types, this case works fine: class Try { public static void main(String[] args) { Ex<String> ex= new Ex<String>(); ex.method("Eclipse1", new Integer(1)); ex.method2(new Integer(1)); ex.method3("Eclipse1"); ex.method4("Eclipse1"); } } class Top<TC> { <TM> void method(TC cTop, TM mTop) { System.out.println("Top"); } <TM> void method2(TM mTop) { System.out.println("Top"); } void method3(TC cTop) { System.out.println("Top"); } <TM> void method4(TC cTop) { System.out.println("Top"); } } class Ex<C> extends Top<C> { @Override <M> void method(C cEx, M mEx) { System.out.println("Ex"); } @Override <M> void method2(M mEx) { System.out.println("Ex"); } @Override void method3(C cEx) { System.out.println("Ex"); } @Override <M> void method4(C cEx) { System.out.println("Ex"); } }
Added MethodVerify test061 & 62. Needs to be uncommented when fix is released. this.tiebreakMethod = this.isRaw ? this : new ParameterizedGenericMethodBinding (this.originalMethod, (RawTypeBinding)null, this.environment);
Tests enabled. Fix released for integration.
Verified for 3.1 RC2 using build I20050610-0010
Verified in I20050610-1200.