Right now I'm trying to do an assignment involving creating a heap that can receive any generic object, and the nodes can compare each other by implementing the Comparable interface. Problem is, I can't find a way to compare generic object like this.
This is what I have so far for the Node class:
private class Node<E> implements Comparable<E>
{
private E data;
private Node left;
private Node right;
//constructors
public Node(E data)
{
this.data = data;
left = null;
right = null;
}
public Node(E data, Node left, Node right)
{
this.data = data;
this.left = left;
this.right = right;
}
//returns current data
public Object getData()
{
return this.data;
}
public int compareTo(E other)
{
return data.compareTo(other);
}
}
When I try to compile, it says "Cannot find symbol -- Method compareTo(E)." The method compareTo() is in the Comparable interface, so I can't understand why this is happening, and I don't know how to fix it. Anyone have any idea?