泛型什么是<?>其实是指? [英] Generics what does <?> actually mean?
问题描述
可能存在重复:
b
什么是List<?>在Java泛型? -
Java泛型中的问号是什么意思?道歉但试图搜寻
<?>
。
关于Java泛型?我知道
> 速记< A extends B>
和< A super B>
,但我从未见过这个问号<?扩展对象>
,它也被称为无界通配符。因此,您可以在泛型中指定任何类型的对象。
例如,
List
类声明为List<?>
,因为它可以是你想要的任何东西的列表。
资源:
Possible Duplicate:
What does List<?> mean in java generics?
What does the question mark in Java generics' type parameter mean?Apologies but it was difficult trying to search for
<?>
.What does mean in regards to Java generics? I understand
<A extends B>
and<A super B>
, but I have never seen this question mark on its own before.解决方案
<?>
is a shorthand for<? extends Object>
, it's also known as an unbounded wildcard. So you can specify any type of object in your generic.For example the
List
class is declared asList<?>
, because it can be a list of anything you want.
Resources:
- Effective java - Generics.pdf
- Java language specification - Type Arguments and Wildcards
- oracle.com - Java tutorials, wildcards
这篇关于泛型什么是<?>其实是指?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!