为什么我不能将我的File对象插入为可比较的?

Hel*_*der 0 java oop object comparable

我得到一个错误符合theTree.insert(new File("a", 1));:The method insert(Comparable) in the type Tree is not applicable for the arguments (File).

当我尝试施放时,theTree.insert((Comparable) new File("a", 1));我得到了其他错误:E xception in thread "main" java.lang.ClassCastException: File cannot be cast to java.lang.Comparable at TreeApp.main(tree.java:134).

为什么我不能传递这个对象?

我的目标:

class FileObject
{
    public String name;
    public int size;

    File(String a, int b)
    {
        this.name = a;
        this.size = b;
    }
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*exR 7

因为你的File班级没有实施Comparable.