Bug 84348

Summary: [1.5] generics T does not match ? super (? extends T)
Product: [Eclipse Project] JDT Reporter: Garret Wilson <garret>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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