Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.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_Eclipse_Generics - Fatal编程技术网

Java泛型类型推断错误

Java泛型类型推断错误,java,eclipse,generics,Java,Eclipse,Generics,我遇到了一个错误,我认为这是一个直接的推论,使用泛型的方法将泛型类的一个版本指定为一个参数,而对于第二个参数,它指定了前一个参数版本所使用的类型 static class GenericClass<T0> { T0 getT() { return null; } static <T1> void func3( GenericClass<T1> a, T1 b ) { } } void tes

我遇到了一个错误,我认为这是一个直接的推论,使用泛型的方法将泛型类的一个版本指定为一个参数,而对于第二个参数,它指定了前一个参数版本所使用的类型

static class GenericClass<T0>
{
    T0 getT()
    {
        return null;
    }

    static <T1> void func3( GenericClass<T1> a, T1 b )
    {

    }
}

void testcase( GenericClass<? extends Integer> a )
{
    GenericClass.func3( a, a.getT() );
}
静态类GenericClass
{
T0 getT()
{
返回null;
}
静态无效func3(一般a类,T1 b类)
{
}
}

void testcase(GenericClass这个例子并不明显,因为
Integer
final
,所以让我们举一个例子,其中
Parent
有两个子类,
Foo
Bar


?extends Parent
表示
Parent
的某些特定子类型。因此
GenericClass
GenericClass
可以用于
genericClassis的地方。我很确定Java从来不会跟踪两个
类型是否相同
,即使可能。啊,是的,现在它有意义了-“Java不知道这两个参数来自同一个源”。因此,第二个参数的类型是独立于get方法派生的,然后它将参数相互比较。谢谢。
"The method func3(GenericClass<T1>, T1) in the type GenericClass is not applicable for the arguments (GenericClass<capture#6-of ? extends Integer>, capture#7-of ? extends Integer)"
static <T1> void func3( GenericClass<? extends T1> a, T1 b )
void testcase( GenericClass<Integer> a )
static <T1> void func3( GenericClass<T1> a, T1 b )
GenericClass<? extends Parent> a = ...;
GenericClass.func3( a, a.getT() );
GenericClass<? extends Parent> a = new GenericClass<Foo>(someFoo);
GenericClass<? extends Parent> b = new GenericClass<Bar>(someBar);
GenericClass.func3( a, b.get());