类定义类名称<> [英] Class definition class name <>

查看:152
本文介绍了类定义类名称<>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class Node< K extends Comparable< ;? 

这个类的定义是什么意思,类是什么类?超K>,V>


解决方案

这是一个通用的类定义。它转换为:


  • 类节点有两种类型作为参数:K和V.

  • 类型K 必须扩展类可比较

  • 可比本身,在这种情况下,我们称它为T。

  • 类型T 必须为K的超类。
  • li>


编辑:好的,因为请求了一个示例,所以此类的一个简单实例化可以是:

  Node< Integer,String> node = new Node< Integer,String>(); 

由于 Integer 类实现了 Comparable< Integer> 它很好地符合上述描述(注意 super 也允许类型T与K相同)。



V没有约束,所以它可以是任何类型。


What's the sense of this class definition, what's kind of class is that?

class Node<K extends Comparable<? super K>,V>

解决方案

This is a generic class definition. It translates to:

  • class Node takes two types as parameters: K and V.
  • the type K must extend the class Comparable
  • the class Comparable itself, in this case, takes some type as parameter, let's call it T.
  • type T must be a superclass of K.

Edit: Ok, since an example was requested, a simple instantiation of this class could be:

Node<Integer, String> node = new Node<Integer, String>();

Since the Integer class implements Comparable<Integer> it fits the above description nicely (note that super also allows type T to the the same type as K).

V has no constraints, so it can be any type.

这篇关于类定义类名称&lt;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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