Bug 90137 - [1.5][compiler] Collections.sort (List<Comparable>) compile error
Summary: [1.5][compiler] Collections.sort (List<Comparable>) compile error
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 94648 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-04 05:48 EDT by Ulrik Restorp CLA
Modified: 2005-05-25 04:32 EDT (History)
3 users (show)

See Also:


Attachments

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