我的insert
-method 上应该有什么签名?我正在为仿制药而苦苦挣扎。在某种程度上,我想要两者Comparable<T>
,T
并且我已经尝试过<Comparable<T> extends T>
.
public class Node<T> {
private Comparable<T> value;
public Node(Comparable<T> val) {
this.value = val;
}
// WRONG signature - compareTo need an argument of type T
public void insert(Comparable<T> val) {
if(value.compareTo(val) > 0) {
new Node<T>(val);
}
}
public static void main(String[] args) {
Integer i4 = new Integer(4);
Integer i7 = new Integer(7);
Node<Integer> n4 = new Node<>(i4);
n4.insert(i7);
}
}