[英]Bound mismatch: The type MyClass1 is not a valid substitute for the bounded parameter <T extends Comparator<T>> of the type Person<T>
I get an error:::Bound mismatch: The type MyClass1 is not a valid substitute for the bounded parameter <T extends Comparator<T>> of the type Person<T>
我收到一个错误::: Bound不匹配:类型MyClass1不是有效的替代
<T extends Comparator<T>> of the type Person<T>
的有界参数<T extends Comparator<T>> of the type Person<T>
Textended <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>>
{
}
The requirement is that MyClass1
needs to match T extends Comparator<T>
. 要求是
MyClass1
需要匹配T extends Comparator<T>
。
For this to be the case, its declaration should be class MyClass1 extends Comparator<MyClass1>
. 为此,其声明应为
class MyClass1 extends Comparator<MyClass1>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.