这里是我的代码:不兼容的类型:java.lang.Object中无法转换至T
package datastructures;
import java.util.Iterator;
public class Stack<T>{
private class Node<T>{
T data;
Node next;
}
private int size;
private Node head;
private Node newNode(T data){
Node new_node = new Node();
new_node.data = data;
new_node.next = null;
return new_node;
}
public Stack(){
size = 0;
head = null;
}
public T pop() {
if(head == null)
return null;
T ret_val = head.data; //Error here
head = head.next;
this.size--;
return ret_val;
}
}
我得到的pop方法的错误,这里是错误:
Error: incompatible types : java.lang.Object cannot be converted to T
我不明白这个错误,我没有在我的代码中的任何地方使用Object。