Community
Participate
Working Groups
I20050928-1300 from http://forum.java.sun.com/thread.jspa?threadID=664224 : class SortedList<E extends Comparable> extends LinkedList<E> { public boolean add(E e){ int index = Collections.binarySearch(this,e); if (index<0) super.add(-index-1,e); return true; } } Peter Ahe says this should not compile, unless the declaration is changed to: public class SortedList<E extends Comparable<E>> extends LinkedList<E>
From spec 15.12.2.7, the inference performs like this: ❖ A << F A is X<E>, F is List<? extends Comparable<? super T>> ❖ If F has the form G<..., Yk-1, ? extends U, Yk+1, ...>, where U involves Tj, then if A has a supertype that is one of: U is Comparable<? super T> ✣ G<..., Xk-1, V, Xk+1, ...>, where V is a type expression. Then this algorithm is applied recursively to the constraint V << U. X<E> << List<? extends Comparable<? super T>> Matching supertype for A is List<E> Recursing into: E << Comparable<? super T> ❖ A << F A is E, F is Comparable<? super T> ✣ If F has the form G<..., Yk-1, ? super U, Yk+1, ...>, where U involves Tj, then if A has a supertype that is one of: U is T ✣ Otherwise, no constraint is implied on Tj ???? Our implementation is handling raw types (for A) at this point, but slightly differently than javac as it seems. I am not aware of any spec'ed behavior describing the handling of inference against raw types (ie. inject erasure of arguments? etc...).
Tuned semantics to refuse inferring from raw types at depth > 0. Added GenericTypeTest#test1017
Created attachment 45226 [details] Proposed patch Patch contains a little more than just this fix.
Created attachment 45270 [details] Better patch
Released fix for 3.3M1 (HEAD)
The fix is quite extensive, this is why not released to 3.2.1, as it got categorized minor to start with.
Verified for 3.3 M1 using build I20060807-2000.