0

なぜエラーが発生するのか誰か教えてもらえますか

暗黙のスーパー コンストラクター 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){

    }
}

ところで、これはキューの練習を行うためのコードです。みなさん、よろしくお願いします!!!

4

4 に答える 4

0

で非プライベート コンストラクターをデフォルト設定していないためですNode class。でデフォルトのコンストラクターを定義するNode classか、別のコンストラクターを呼び出す必要がありNode classますQueue class

または、このクレイジーなソリューションを回避してください。Queue は、派生ではなく、Node オブジェクトを保持する可能性があります。Node class

于 2013-03-07T17:29:57.860 に答える
0

問題は、 がありQueue2<T, Item> extends Node<T>、の引数なしのコンストラクターがなく、 のコンストラクターがどのコンストラクターが呼び出されることになっているかを示していないことです。Node<T>Queue2<T, item>Node<T>

Queue2<T, Item>実際にはのサブクラスになりたくないのでNode<T>( is-a 関係ではなく、 has-a 関係があります)、これを変更します。

public class Queue2<T, Item> extends Node<T> {

これに:

public class Queue2<T, Item> {
于 2013-03-07T17:31:38.513 に答える