泛型什么是<?>其实是指? [英] Generics what does <?> actually mean?

查看:122
本文介绍了泛型什么是<?>其实是指?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

什么是List<?>在Java泛型? -

Java泛型中的问号是什么意思?

b

道歉但试图搜寻<?>



关于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 as List<?>, because it can be a list of anything you want.


Resources:

这篇关于泛型什么是&lt;?&gt;其实是指?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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