[英]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.