java - 绑定(bind)不匹配 : The type MyClass1 is not a valid substitute for the bounded parameter <T extends Comparator<T>> of the type Person<T>

标签 java generics

我收到错误:::绑定(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/

相关文章:

java - 定期更新我的应用程序的 UI

swift - 使用 swift 转换英尺/英寸

java - 为什么允许 "extends T"而不允许 "implements T"?

java - 将 JPanel 添加到 JFrame 中

java - JDK8 javac/Eclipse Luna 类型推断的差异?

r - R内部的通用 "classes"

java - 不能包含具有不同参数的相同接口(interface)吗?

java - 包含具有通用 Map.Entry 参数的方法

java - 启动线程作为最终类的构造函数的最后一条语句

java - 使用 Jersey 在浏览器上显示 JSON