下面的代码已经简化成了必要的部分以便于提问:
public class GenericTest
{
private interface CopyInterface<T extends CopyInterface<T>>
{
public void copyFrom(T source);
}
public void testMethod()
{
CopyInterface<?> target;
CopyInterface<?> source;
target.copyFrom(source);
}
}
这会导致编译器产生以下错误信息:
在类型GenericTest.CopyInterface中,方法copyFrom(capture#1-of ?)不适用于参数(GenericTest.CopyInterface) GenericTest.java /ACAF/src/de/tmasoft/acaftest/attributes line 14 Java Problem
当我为变量目标使用原始类型时,只会得到一个原始类型警告。有没有一种方法可以在不使用原始类型的情况下编译它?
<T extends CopyInterface<T>>
,而不是例如<T extends CopyInterface<?>>
或<T extends CopyInterface<K>>
吗? - Nicolas Mattia