这个类声明在Java中意味着什么? [英] What does this class declaration mean in Java?

查看:89
本文介绍了这个类声明在Java中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:class BinarySearchTree< p> ; T扩展了Comparable< super T>>

现在,请你解释一下括号内的内容和< ;? super T>



您可以引荐我的任何良好来源?感谢。

解决方案

这声明了一个具有单个泛型类型参数的类。由于对于二叉搜索树,它必须能够比较两个项目,这需要指定,以便编译器可以验证它。



尖括号中的部分是类型参数 T 及其约束:


  • 无论 T 是,它应该扩展 Comparable < T extends Comparable< ...>>> )。

  • 所有 Comparable 应该能够比较自己和 T 或超级 T < ;? super T> )。



由于 T 通常可以是任何限制选择的类型感觉实现一个搜索树。


I just learn up to tree and one thing I don't understand about it is the class declaration:

for example: class BinarySearchTree<T extends Comparable<? super T>>.

Now, can you please explain me what is in the bracket and the "<? super T>"?

Any good source you can refer me to? Thanks.

解决方案

This declares a class with a single generic type parameter. Since for the binary search tree it's imperative that it can compare two items, this needs to be specified so that the compiler can verify it.

The part in angle brackets is the type parameter T and a constraint for it which says:

  • Whatever T is, it should extend Comparable (<T extends Comparable<...>>).
  • Said Comparable should be able to compare itself to either T or a super-class of T (<? super T>).

Since T could usually be anything this constrains the choice to types where it makes sense to implement a search tree for.

这篇关于这个类声明在Java中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆