Bug 90137

Summary: [1.5][compiler] Collections.sort (List<Comparable>) compile error
Product: [Eclipse Project] JDT Reporter: Ulrik Restorp <ulrik.restorp>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P3 CC: g.castaldi, gunnar, loskutov
Version: 3.1   
Target Milestone: 3.1 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Ulrik Restorp CLA 2005-04-04 05:48:42 EDT
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>>
Comment 1 Philipe Mulet CLA 2005-04-15 04:35:07 EDT
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>>
----------
Comment 2 Philipe Mulet CLA 2005-04-15 04:38:35 EDT
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
Comment 3 Philipe Mulet CLA 2005-04-21 09:11:15 EDT
Released
Comment 4 Ulrik Restorp CLA 2005-04-27 08:38:26 EDT
ok. works fine.
Comment 5 Philipe Mulet CLA 2005-05-12 06:12:18 EDT
*** Bug 94648 has been marked as a duplicate of this bug. ***