无界通配符类型 List<?> 和无界通配符类型有什么区别?和原始类型列表? [英] What's the difference between unbounded wildcard type List<?> and raw type List?
问题描述
你能帮我理解无界通配符类型列表和原始类型列表之间的区别吗?
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
除此之外,任何人都可以帮助我理解什么是有界类型参数列表?
List<E extends Number> c;
推荐答案
以下是三者的总结:
List
:一个没有类型参数的列表.它是一个列表,其元素可以是任何类型——元素可以是不同类型.
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>
:具有无界类型参数的列表.它的元素具有特定但未知的类型;元素的类型必须相同.
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
的类型参数的列表.为 T
提供的类型必须是扩展 E
的类型,否则它不是参数的有效类型.
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<?> 和无界通配符类型有什么区别?和原始类型列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!