Java中无界的通配符 [英] Unbounded wildcards in Java
本文介绍了Java中无界的通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无界通配符例如<?>
和一个有界通配符,其边界是 Object
,例如< ;?扩展对象>
?
Is there ever a difference between an unbounded wildcard e.g. <?>
and a bounded wildcard whose bound is Object
, e.g. <? extends Object>
?
我记得有些地方在泛型的早期草稿中有所不同,但是找不到这个源代码。 / p>
I recall reading somewhere that there was a difference in the early drafts of generics, but cannot find that source anymore.
推荐答案
作为pedntry的一个要点,如果类/接口/构造函数/方法声明一个绑定(除<
$ b
As a point of pedntry, there is a difference if the class/interface/constructor/method declares a bound (other than extends Object
).
interface Donkey<T extends Thing> { }
...
Donkey<? extends Object> foo; // FAIL
这篇关于Java中无界的通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文