I get an error in line with theTree.insert(new File("a", 1));: The method insert(Comparable) in the type Tree is not applicable for the arguments (File).
And when I try to cast as such theTree.insert((Comparable) new File("a", 1)); I get other error: Exception in thread "main" java.lang.ClassCastException: File cannot be cast to java.lang.Comparable at TreeApp.main(tree.java:134).
Why can’t I pass this object?
My object:
class FileObject
{
public String name;
public int size;
File(String a, int b)
{
this.name = a;
this.size = b;
}
}
You need to implement
Comparable<File>References:
ComparableNote: Please provide
compareToimplementation in contract withequalsmethod.