我收到错误:::绑定(bind)不匹配:类型 MyClass1 不是有界参数 <T extends Comparator<T>> of the type Person<T>
的有效替代品
import java.util.Comparator;
public class Test
{
public static void main(String[] args)
{
Person<MyClass1> person2 = new Person<>(); // Bound mismatch: The type MyClass1 is not a valid substitute for the bounded parameter <T extends Comparator<T>> of the type Person<T>
}
}
class MyClass1<T extends Comparator<T>> implements Comparator<T>
{
@Override
public int compare(T o1, T o2)
{
return 0;
}
}
class Person<T extends Comparator<T>>
{
}
最佳答案
要求是 MyClass1
需要匹配T extends Comparator<T>
.
对于这种情况,其声明应为 class MyClass1 extends Comparator<MyClass1>
.
关于java - 绑定(bind)不匹配 : The type MyClass1 is not a valid substitute for the bounded parameter <T extends Comparator<T>> of the type Person<T>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52581617/