JDK-4999413 : File does not implement Comparable
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-02-23
  • Updated: 2004-02-23
  • Resolved: 2004-02-23
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 02/23/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
java.io.File implements java.lang.Comparable but not the genericized Comparable<File>, so that I cannot call Collections.sort() on a List<File>:

cannot find symbol
symbol  : method sort(java.util.List<java.io.File>)
location: class java.util.Collections
        Collections.sort(files);
                   ^

It works fine if I cast the argument to a raw List! But that still causes an unchecked warning:

warning: [unchecked] unchecked method invocation: <T>sort(java.util.List<T>) in java.util.Collections is applied to (java.util.List)
        Collections.sort((List) files);
                   ^


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.*;

public class SortFileList
{
    public void sortFileList()
    {
        List<File> files = new ArrayList<File>();
        Collections.sort(files);
    }
}


---------- END SOURCE ----------
(Incident Review ID: 239913) 
======================================================================

Comments
EVALUATION Already handled as part of 4964490. -- iag@sfbay 2004-02-23
23-02-2004