Community
Participate
Working Groups
Incorrectly, a class TestImpl<T> extending another class AbstractTest<T> which in turn implements a generic method <S extends T> void doTest(S[] a) in an interface Test<T> is reported to not implement Test<T>.doTest(S[]). The error message doesn't go away if Project > Clean... is choosen on the menubar, as in bug 81719. Below I include example code to replicate this bug. I have also filed another bug probably related to this one: bug 81719. --- Test.java --------------------------------------------------------- public interface Test<T> { <S extends T> void doTest(S[] a); } --- AbstractTest.java ------------------------------------------------ public abstract class AbstractTest<T> implements Test<T> { public <S extends T> void doTest(S[] a) { g(a); } protected abstract void g(T[] a); } --- TestImpl.java ----------------------------------------------------- import java.util.Arrays; // Eclipse incorrectly complains that "The type TestImpl<T> must implement the // inherited abstract method Test<T>.doTest(S[])". It doesn't help to clean // the project to remove this error message, as in bug 81719. public class TestImpl<T> extends AbstractTest<T> { protected void g(T[] a) { System.out.println(Arrays.toString(a)); } } --- Main.java -------------------------------------------------------- public class Main { public static void main(String[] args) { Test<Integer> test=new TestImpl<Integer>(); Integer[] integers=new Integer[10]; for(int i=0; i<10; ++i) integers[i]=i; test.doTest(integers); } }
Philippe: can you please take a look at this one? Here's the minimal testcase: interface I<T> { <S extends T> void doTest(S[] a); } abstract class AbstractTest<U> implements I<U> { public <V extends U> void doTest(V[] a) {} } class Test<M> extends AbstractTest<M> {} The problem is that when we attempt to do a bounds check with the method doTest, we fail when trying to verify the class Test. When AbstractTest asks, the variable T is correctly replaced with V, but when Test asks, M does not replace T so the type variable S thinks it is not compatible with M.
Added support for cloning type variables, with substituted bounds when instantiating a parameterized method binding of a generic method. Added GenericTypeTest#test456. Fixed
Verified in I20050214