Bug 84251 - [1.5][compiler] lower bounded wildcard misunderstood
Summary: [1.5][compiler] lower bounded wildcard misunderstood
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-02 13:45 EST by Maximiliano Sanchez de Bustamante CLA
Modified: 2005-02-15 05:22 EST (History)
0 users

See Also:


Attachments
Complete test case (834 bytes, text/plain)
2005-02-02 14:12 EST, Olivier Thomann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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).