简体   繁体   English

为什么我的通用实现不起作用? (扩展了可比性 <? super T> &gt;)

[英]Why is my generic implementation not working? (extends Comparable<? super T>>)

I am implementing a Binary Search Tree with BinaryNode<T> that holds the information. 我正在使用BinaryNode<T>实现一个包含信息的Binary搜索树。 In my tree class I have this line of code: 在我的树类中,我有以下代码行:

public class BST<T> implements BSTInterface<T extends Comparable<? super T>>

This is causing many errors such as: 这导致许多错误,例如:

BST.java:10: error: > expected
public class BST<T> implements BSTInterface<T extends Comparable<? super T>>
                                          ^
BST.java:10: error: <identifier> expected
public class BST<T> implements BSTInterface<T extends Comparable<? super T>>
                                                                           ^

I am not sure why this isn't working because that line of code works for my interface. 我不确定为什么这行不通,因为那行代码适用于我的界面。 Any help would be much appreciated! 任何帮助将非常感激! I am probably making some stupid mistake. 我可能正在犯一些愚蠢的错误。

I think you intended to write 我想你打算写

public class BST<T extends Comparable<? super T>> implements BSTInterface<T>

You have to put the bounds on T at the first mention of T . 你必须把上界T在第一次提到T

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

相关问题 如何返回一个通用数组<T extends Comparable<? super T> &gt; 在 Java 中? - How return a generic array of <T extends Comparable<? super T>> in Java? 怎么会 <T extends Comparable<T> &gt;作为 <T extends Comparable<? super T> &gt;? - How come <T extends Comparable<T>> working as <T extends Comparable<? super T>>? 泛型的解释<T extends Comparable <? superT >>在collection.sort /可比代码? - Explanation of generic <T extends Comparable<? super T>> in collection.sort/ comparable code? 为什么T扩展了Comparable <? super T> 包括T? 含义包括可比较 <T> ? - Why does T extends Comparable <? super T> include T? Meaning includes Comparable<T>? 为什么通用约束T扩展了可比性 <T> 还不足以避免演员阵容? - Why generic constraint T extends Comparable<T> is not sufficient to avoid a cast? Java泛型-为什么不允许我做可比 <? extends T> 而不是可比 <? super T> ? - Generics in Java - Why I am not allowed to do Comparable<? extends T> instead of Comparable<? super T>? 问题 <T extends Comparable<? super T> &gt; - Issue with <T extends Comparable<? super T>> 有问题<t extends comparable<? super t> ></t> - Problem with <T extends Comparable<? super T>> 静态的 <T extends Number & Comparable<? super Number> &gt; - static <T extends Number & Comparable<? super Number>> 为什么可比较的实现工作 - Why Comparable implementation working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM