Bug 84348 - [1.5] generics T does not match ? super (? extends T)
Summary: [1.5] generics T does not match ? super (? extends T)
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-03 12:04 EST by Garret Wilson CLA
Modified: 2005-02-19 18:54 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Garret Wilson CLA 2005-02-03 12:04:49 EST
I20050202-0800-win32

Inside the following method:

public static <T> void myMethod(final List<? extends File> fileList)

I attempt to sort the list using:

Collections.sort(fileList, new Comparator<File>(){...});

I get the following error: "The method sort(List<T>) in the type Collections is
not applicable for the arguments (List<? extends File>, new Comparator<File>(){})"

The Collections.sort() signature is:

public static <T> void sort(List<T> list, Comparator<? super T> c)

Substituting, I get (File super (? extends File)), which means Comparator<File>
should match the signature because File is always a superclass of anything that
extends File.

This worked under 3.1 M4.

Garret
Comment 1 Frederic Fusier CLA 2005-02-16 06:36:01 EST
Following test case compiles without any error:

import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Test {
	public static <T> void myMethod(final List<? extends File> fileList) {
		Collections.sort(fileList, new Comparator<File>(){
			public int compare(File f1, File f2) { return 0; }
		});
	}
}

Surely fixed with latest 1.5 changes...
Comment 2 Garret Wilson CLA 2005-02-19 11:03:45 EST
Yes---I've verified this now compiles under 3.1 M5.

Garret