なぜエラーが発生するのか誰か教えてもらえますか
暗黙のスーパー コンストラクター 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;
}
}
これがスーパークラスです...ゲッターとセッターが完全ではないことに気づきましたが、それは私のエラーとは無関係だと思いますか? :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){
}
}
ところで、これはキューの練習を行うためのコードです。みなさん、よろしくお願いします!!!