我正在創建一個通用鏈接堆棧。此錯誤時顯示出創造下一個新節點:錯誤參數類型E隱藏類型E
private class Node<E> {
什麼是錯我的代碼導致此?
public class LinkedStack<E> implements StackBehavior<E> {
private class Node<E> {
private E element;
private Node<E> next;
private Node(E element) {
this.element = element;
this.next = null;
}
private Node(E element, Node<E> next) {
this.element = element;
this.next = next;
}
}
private Node<E> top = null;
public void push(E item) {
top = new Node<E>(item, top);
}
public E pop() {
if (top == null) {
throw new EmptyStackException("Pop error: Stack is empty.");
}
E item = top.element;
top = top.next;
return item;
}
public E peek() {
if (top == null) {
throw new EmptyStackException("Peek error: Stack is empty.");
}
return top.element;
}
public boolean isEmpty() {
return (top == null);
}
public String toString() {
Node<E> curr = top;
String stringStack = "top";
while (curr != null) {
stringStack += " --> " + curr.element;
curr = curr.next;
}
return stringStack;
}
}