繁体   English   中英

Java泛型绑定不匹配递归类型

[英]Java generics bound mismatch recursive type

我有一个奇怪的问题,我不知道该如何解决。 这是出现错误的类的声明:

public class DList<V extends Comparable<V>> { ...

在下面,我有一个具有以下签名的方法:

public DList<DList<V>> split(int steps) { ...

这给了我具体的错误

Bound mismatch: The type DList<V> is not a valid substitute for the bounded parameter <V extends Comparable<V>> of the type DList<V>

到目前为止,问题在于以下类接受类型V,该类型的上限为Comparable,但不接受递归类型DList。 如何解决这种类型的“递归”并摆脱错误?

DList工具Comparable

public class DList<V extends Comparable<V>> implements Comparable<DList<V>> {
    @Override public int compareTo(DList<V> other) {
        return 0;
    }
}

然后确保V的替代品有界:

public class Other {

    public static <X extends Comparable<X>> DList<DList<X>> split(int steps) {
        return null;
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM