简体   繁体   English

错误无法推断出节点<>的类型参数

[英]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. 您看到的错误掩盖了Node构造函数接受参数的事实,因此无法调用no-args构造函数。

When declaring a custom constructor in a class, the default no-args constructor is not automatically available anymore. 在类中声明自定义构造函数时,默认的no-args构造函数不再自动可用。

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. 可以使用所需的args(例如t ,下一个Node ,上一个Node )对构造函数调用进行参数化,也可以在Node类中添加一个无参数的构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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