无界通配符类型List<>的区别是什么?和原始类型列表? [英] What's the difference between unbounded wildcard type List<?> and raw type List?

查看:244
本文介绍了无界通配符类型List<>的区别是什么?和原始类型列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否帮我理解无界通配符列表原始类型列表之间的区别?

 列表与LT;?> b; //无界通配符类型
列出a; //原始类型



除此之外,任何人都可以帮助我理解什么是一个有界的类型参数列表

  List< E extends Number> C; 


解决方案

以下是三个概要:




  • List :没有类型参数的列表。这是一个列表,其元素可以是任何类型 - 元素可以是不同的类型


  • List<?> :带有无限类型参数的列表。它的元素是一个特定的,但未知的类型; 元素必须全部是相同的类型

  • $ c>:一个名为 T 的类型参数列表。提供的 T 类型必须是一个扩展 E 的类型,或者它不是该参数的有效类型。

Could you help me understand the difference between unbounded wildcard type List and raw type List?

List<?> b;    // unbounded wildcard type
List a;       // raw type


Along with this can anybody help me understand what is a bounded type parameter list?

List<E extends Number> c;

解决方案

Here's a summary of the three:

  • List: A list with no type parameter. It is a list whose elements are of any type -- the elements may be of different types.

  • List<?>: A list with an unbounded type parameter. Its elements are of a specific, but unknown, type; the elements must all be the same type.

  • List<T extends E>: A list with a type parameter called T. The supplied type for T must be of a type that extends E, or it is not a valid type for the parameter.

这篇关于无界通配符类型List&lt;&gt;的区别是什么?和原始类型列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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