gpt4 book ai didi

java - 如何修复Java中的 'Bound mismatch'

转载 作者:行者123 更新时间:2023-12-02 03:27:28 24 4
gpt4 key购买 nike

我尝试使用泛型扩展 Treap 类中的 AbstractTreap 类。

我下载了 TreapNode 和 AbtractTreap 文件,并尝试实现 Treap 类作为练习。

结果应该是像这样的 Treap:https://www.geeksforgeeks.org/treap-a-randomized-binary-search-tree/

public class Treap<E> extends AbstractTreap<E>

public final class TreapNode<E extends Comparable<? super E>>
implements Comparable<TreapNode<E>>, java.util.Comparator<TreapNode<E>>

public abstract class AbstractTreap<E extends Comparable<? super E>>

错误:

Bound mismatch: The type E is not a valid substitute for the bounded parameter > of the type AbstractTreap

最佳答案

AbstractTreap 有一个通用参数,它是 Comaparable。如果扩展它并传递该参数,则必须确保它至少代表相同的边界(如果不是更严格的话)。例如:

public class Treap<E extends Comparable<? super E>> extends AbstractTreap<E>

关于java - 如何修复Java中的 'Bound mismatch',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56902581/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com