Community
Participate
Working Groups
Platform: 3.1M6 The following works: List<Comparable<Object>> lObj = new ArrayList<Comparable<Object>> (); Collections.sort (lObj); But not these two examples: 1) List<Comparable> lComp = new ArrayList<Comparable> (); Collections.sort (lComp); Error description: Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments (List<Comparable>) since the type Comparable is not a valid substitute for the bounded parameter <T extends Comparable<? super T>> 2) List<Comparable<String>> lStr = new ArrayList<Comparable<String>> (); Collections.sort (lStr); Error description: Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments (List<Comparable<String>>) since the type Comparable<String> is not a valid substitute for the bounded parameter <T extends Comparable<? super T>>
1) should generate an unchecked warning 2) should still be an error ---------- 1. WARNING in X.java (at line 11) Collections.sort (lComp); ^^^^^^^^^^^^^^^^^^^^^^^^ Type safety: Unchecked invocation sort(List<Comparable>) of the generic method sort(List<T>) of type Collections ---------- ---------- 2. ERROR in X.java (at line 15) Collections.sort (lStr); ^^^^ Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments (List<Comparable<String>>) since the type Comparable<String> is not a valid substitute for the bounded parameter <T extends Comparable<? super T>> ----------
Added GenericTypeTest#test607. Changed generic method type argument inference to tolerate unchecked conversion, and then issue an unchecked method invocation warning. Fixed, will release changes along with fix for bug 84496
Released
ok. works fine.
*** Bug 94648 has been marked as a duplicate of this bug. ***