您的位置:首页 > 其它

A<T extends B> and A <? extends B>

2016-04-23 22:11 344 查看
Refer to
http://stackoverflow.com/questions/5211548/what-is-the-difference-between-at-extends-b-and-a-extends-b
First of all, those are completely different constructs used in different contexts.

A<T extends B>
is a part of generic type declaration such as

public class A<T extends B> { ... }

It declares generic type
A
with type parameter
T
, and introduces a bound on
T
, so that
T
must be a subtype of
B
.

A<? extends B>
is a parameterized type with wildcard, it can be used in variable and method declarations, etc, as a normal type:

A<? extends B> a = ...;

public void foo(A<? extends B> a) { ... }

Variable declaration such as
A<? extends B> a
means that type of
a
is
A
parameterized with some subtype of
B
.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: