gpt4 book ai didi

java - 如何正确实现此类?

转载 作者:行者123 更新时间:2023-11-30 06:56:51 25 4
gpt4 key购买 nike

作为一项家庭作业,我们必须实现一个附加类 - SortedList- 并使用链接的二叉搜索/排序树来实现它。

这是界面的类标题(老师给的):

public interface SortedListInterface<T extends Comparable<? super T>> {

这是我实现它的时候:

public class BinaryTree<T> implements SortedListInterface<T> {

出现错误:Bound mismatch: The type T is not a valid substitute for the bounded parameter <T extends Comparable<? super T>> of the type
SortedListInterface<T>

我该如何解决这个问题?由于这个错误,到目前为止我无法测试我的类(class),我们将不胜感激任何帮助

最佳答案

因为您将 T 作为类型参数传递给 SortedListInterface,它必须满足 SortedListInterface 指定的边界。但是您没有为您在 BinaryTree 上声明的 T 指定任何边界,因此出现错误。

BinaryTree 中的 T 指定与 SortedListInterface 中的 T 相同的边界。

关于java - 如何正确实现此类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34004713/

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