简体   繁体   中英

error cannot infer type arguments for node<>

When i try to create a Node, appear "error cannot infer type arguments for node<>" why? I do not know why it could be

public class LinkedDoubleEndedQueue<T> implements DoubleEndedQueue<T> {

    private static class Node<E> {
        private E elem;
        private Node<E> next;
        private Node<E> prev;

        public Node(E x, Node<E> nxt, Node<E> prv) {
            elem = x;
            next = nxt;
            prev = prv;
        }
    }

    private Node<T> first, last;

@Override
public void addFirst(T x) {
    // TODO Auto-generated method stub
        Node<T> node = new Node<>();


}

The error you see is masking the fact that your Node constructor takes arguments, therefore the no-args constructor cannot be invoked.

When declaring a custom constructor in a class, the default no-args constructor is not automatically available anymore.

Either parametrize your constructor invocation with the required args (eg t , the next Node , the previous Node ) or add a no-args constructor to the Node class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM