Bug 84251

Summary: [1.5][compiler] lower bounded wildcard misunderstood
Product: [Eclipse Project] JDT Reporter: Maximiliano Sanchez de Bustamante <maxi_sb>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
Complete test case none

Description Maximiliano Sanchez de Bustamante CLA 2005-02-02 13:45:19 EST
I'am following the generic's tutorial of "Generics in the Java Programming
Language" downloaded fro mthe sun website. When I write the code to use the
lower bound wildcard, the compiler give me an error in the calling to writeAll
method. the error is:

The method writeAll(Collection<T>, Sink<? super T>) in the type Test is not
applicable for the arguments (Collection<String>, Sink<Object>)

If I compile it outside eclipse, with javac, works well, and execute fine. I use
JDK 1.5.0_01. I define JDK 1.5.0_01 like my default installed JRE, and set
compiler compatibility to 5.0
I send you the class code.

public class Test {

    private <T> T writeAll(Collection<T> coll, Sink<? super T> snk) { 
        T last = null;
        for (T t : coll) { 
            last = t;
            snk.flush(last);
        }
        return last;
    }

    public void test1() {
        Sink<Object> s = new SimpleSinkImpl<Object>();
        Collection<String> cs = new ArrayList<String>();
        cs.add("hello!");
        cs.add("goodbye");
        cs.add("see you");
        
        String str = this.writeAll(cs, s);  
    }

    public static void main(String[] args) {
        Test test = new Test();
        
        test.test1();
    }
Comment 1 Olivier Thomann CLA 2005-02-02 14:12:27 EST
Created attachment 17635 [details]
Complete test case

We report:
----------
1. ERROR in c:\tests_sources\Test.java
 (at line 28)
	String str = this.writeAll(cs, s);  
			  ^^^^^^^^
The method writeAll(Collection<T>, Sink<? super T>) in the type Test is not
applicable for the arguments (Collection<String>, Sink<Object>)
----------
1 problem

javac compiles fine.
Comment 2 Philipe Mulet CLA 2005-02-15 05:22:15 EST
Added GenericTypeTest#test500.
Was resolved when tuned generic method type argument inference (JLS 15.12.2.7&8).