[英]Java: Extending class with generics
How would I extend this class 我将如何扩展这堂课
public class BST<E extends Comparable<E>> implements Iterable<E>
I am trying to create AVL tree class which extends BST. 我正在尝试创建扩展BST的AVL树类。
I have 我有
public class AVL extends BST<E>
but i'm getting error cannot find symbol for the E. I have tried 但是我遇到错误,找不到E的符号。
public class AVL<E extends BST<E>>
and receive error as well E1 extends BST but E2 extends Comparable. 并且接收错误,E1扩展了BST,但E2扩展了Comparable。
Have it like this: 像这样:
public class AVL<E extends Comparable<E>> extends BST<E>
Why? 为什么?
You need to satisfy generic constraint of parameter E
of BST
class - <E extends Comparable<E>>
and as you can see in the definition above, you are meeting that requirement. 您需要满足
BST
类的参数E
的一般约束- <E extends Comparable<E>>
并且正如您在上面的定义中看到的那样,您正在满足该要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.