Bug 81721 - [compiler][1.5] Correct use of generic interfaces give compiler error
Summary: [compiler][1.5] Correct use of generic interfaces give compiler error
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal with 1 vote (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-21 05:07 EST by Thomas Barregren CLA
Modified: 2005-02-15 05:45 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Barregren CLA 2004-12-21 05:07:21 EST
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);
    }
}
Comment 1 Kent Johnson CLA 2005-01-11 15:27:00 EST
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.
Comment 2 Philipe Mulet CLA 2005-01-13 18:19:51 EST
Added support for cloning type variables, with substituted bounds when
instantiating a parameterized method binding of a generic method.

Added GenericTypeTest#test456.
Fixed
Comment 3 Jerome Lanneluc CLA 2005-02-15 05:45:25 EST
Verified in I20050214