A newbie question (possibly duplicate too) but can someone point me what's wrong with the below code:
public class Node<T> implements Comparable<Node<T>> {
protected final Comparable<T> data;
protected final List<Node<T>> adj;
public Node(Comparable<T> data) {
this.data = data;
adj = new ArrayList<Node<T>>();
}
@Override
public int compareTo(Node<T> other) {
return data.compareTo(other.data);
}
}
The compareTo method shows a compilation error: compareTo(T) in Comparable cannot be applied to (java.lang.Comparable).
Alternatively I tried using public class Node<T extends Comparable<? super T>> implements Comparable<Node<T>> but then if I add this Node in, say, an ArrayList> then I am not able to use the contains method of ArrayList.
I'd be very thankful if someone points me out the difference.