DESKTOP-P665UA2_20200910-石家雨
1、遇到的问题
public boolean add( E e ) {
if( first == null ) {
first =new Node<>( null , e , null );
last = first;
}else {
final Node<E> old = this.last;
Node<E> n = new Node<>( old , e , null );
old.next = n;
this.last = n;
}
count++;
return true ;
}
此时
first =new Node<>( null , e , null );
Node<E> n = new Node<>( old , e , null );
报了一个错误 Cannot infer type arguments for Node 无法推断Node的类型参数
2、解决
private Node(Node<X> previous, Node<X> next, X item) {
super();
this.previous = previous;
this.next = next;
this.item = item;
}
因为我把构造方法里的参数列表调换了顺序,应该写成
first =new Node<>( null , null , e );
Node<E> n = new Node<>( old , null , e );
3、吐槽
今天讲的内容没怎么听懂,很蒙
近期评论