Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 内部类泛型-不兼容类型_Java_Generics_Incompatibletypeerror - Fatal编程技术网

Java 内部类泛型-不兼容类型

Java 内部类泛型-不兼容类型,java,generics,incompatibletypeerror,Java,Generics,Incompatibletypeerror,我似乎不明白为什么这些类型是不兼容的,是不是因为它们在不同的类级别上?我就是不太明白为什么 public class PrependLinearListImpl<T>{ private Node<T> first; private class Node<T> { private T head; private Node<T> tail; Node(T head) {

我似乎不明白为什么这些类型是不兼容的,是不是因为它们在不同的类级别上?我就是不太明白为什么

public class PrependLinearListImpl<T>{
    private Node<T> first;

    private class Node<T> {
        private T head;
        private Node<T> tail;
        Node(T head) {
            this.head = head;
            this.tail = first;
            first = this;
        }
    }

}
公共类prependlinearListPL{
私有节点优先;
私有类节点{
私人T型头;
私有节点尾部;
节点(T头){
这个头=头;
this.tail=第一;
第一个=这个;
}
}
}

这是因为
prependlinearListPL.Node
已经从其外部类继承了泛型参数。没有必要重新定义泛型组件

以下各项应按原样工作:

public class PrependLinearListImpl<T>{
    private Node first;

    private class Node {
        private T head;
        private Node tail;
        Node(T head) {
            this.head = head;
            this.tail = first;
            first = this;
        }
    }

}
公共类prependlinearListPL{
私有节点优先;
私有类节点{
私人T型头;
私有节点尾部;
节点(T头){
这个头=头;
this.tail=第一;
第一个=这个;
}
}
}

如果
节点
静态的
,则有必要提供它自己的泛型参数。

这是因为
PrependlinearListPL.Node
已经从它的外部类继承了泛型参数。没有必要重新定义泛型组件

以下各项应按原样工作:

public class PrependLinearListImpl<T>{
    private Node first;

    private class Node {
        private T head;
        private Node tail;
        Node(T head) {
            this.head = head;
            this.tail = first;
            first = this;
        }
    }

}
公共类prependlinearListPL{
私有节点优先;
私有类节点{
私人T型头;
私有节点尾部;
节点(T头){
这个头=头;
this.tail=第一;
第一个=这个;
}
}
}

如果
Node
static
,那么就必须提供它自己的泛型参数。

确切的错误是什么?你有两个不同的
T
s。嗨,不知何故,我认为内部类T与外部类T完全相同,我是否应该将其重命名为“E”并将其扩展为“T”?错误如下:类型不兼容。必需:PrependlinearListPL.Node发现:PrependlinearListPL.Node确切错误是什么?您有两个不同的
T
s.Hi,不知何故,我认为内部类T与外部类T完全相同,我是否应该将其重命名为“E”并将其作为“T”的扩展?错误如下:类型不兼容。必需:找到PrependlinearListPL.Node:PrependlinearListPL.Node