Community
Participate
Working Groups
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(); }
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.
Added GenericTypeTest#test500. Was resolved when tuned generic method type argument inference (JLS 15.12.2.7&8).