谁能告诉我为什么我得到一个错误说
隐式超级构造函数 Node() 未定义。必须显式调用另一个构造函数
我知道在某些情况下,当 Java 编译器版本与代码混合使用时,eclipse 会出现此错误,但对我而言并非如此。这是我的代码,错误在 Queue2 构造函数的 Queue2 类中。
import java.util.NoSuchElementException;
public class Queue2<T, Item> extends Node<T> {
private Node<T> head;
private Node<T> tail;
// good practice to initialize all variables!
public Queue2() {
head = null;
tail = null;
}
public void enqueue(T newData) {
// make a new node housing newData
Node<T> newNode = new Node<T>(newData);
// point _head to newNode if queue is empty
if (this.isEmpty()) {
_head = newNode;
}
// otherwise, set the current tail’s next
// pointer to the newNode
else {
_tail.setNext(newNode);
}
// and make _tail point to the newNode
_tail = newNode;
}
// in class Queue<Type> …
public Type dequeue() {
if (this.isEmpty()) {
return null;
}
// get _head’s data
Type returnData = _head.getData();
// let _head point to its next node
_head = _head.getNext();
// set _tail to null if we’ve dequeued the
// last node
if (_head == null){
_tail = null;
}
return returnData;
public boolean isEmpty() {
// our Queue is empty if _head
// is pointing to null!
return _head == null;
}
}
这是超级类......我意识到getter和setter并不完整,但我相信这与我的错误无关?:S
public class Node<Type> {
private Type _data;
private Node<Type> _nextNode;
public Node(Type newData) {
_data = newData;
_nextNode = null;
}
public void setNext(Node<T> newNextNode){
}
public Node<Type> getNext() {
}
public Type getData() {
}
public void setData(Node<T> newData){
}
}
顺便说一句,这只是一些代码来做一些队列练习!先谢谢大家了!!!