<?>和<? extends Object>的区别

From a practical point to most people, <? extends Object> is the same as <?>, like everyone have suggested here.

However, they differ in two very minor and subtle points:

  1. The JVMS (Java Virtual Machine Specification) has a special specification for the unbounded wildcards, as ClassFileFormat-Java5 specifies that unbounded wildcard gets encoded as *, while encodes a Object-bounded wildcard as +Ljava/lang/Object;.  Such change would leak through any library that analyzes the bytecode.  Compiler writers would need to deal with this issue too.  From revisions to "The class File Format"

  2. From reifiablity standpoint, those are different.  JLS 4.6 and 4.7 codify List<?> as a reifiable type, but List<? extends Object> as a erasured type.  Any library writer adding .isReifiable() (e.g. mjc lib) needs to account for that, to adhere to the JLS terminology.  From JLS 4.6 and 4.7.


这个解释超牛逼,先把它记下来。它来自于http://stackoverflow.com/questions/2016017/unbounded-wildcards-in-java/2016382#2016382

update:

以下是我翻译的,求指点。

从使用它的角度来看,<? extends Object>和<?>是一样的,就像每个人所建议的。
尽管如此,他们有两个细微的区别:
1,JVMS 对无界通配符有个特定的规范,ClassFileFormat-Java5的规范是,无界通配符将被编码成*,而以Object为上界的通配符(? extends Object)将被编码成+Ljava/lang/Object。这个区别在类库分析字节码时会带来一个漏洞。编译器编写者将不得不处理这个问题;可参照 revisions to "The class File Format"。
2,从可信赖的角度看,它们是不同的。JLS4.6和4.7认为 List<?>是一个可信赖的类型,但是List<? extends Object>是会被擦除掉的类型。任何库的编写者在考虑这个问题时需要使用.isReifiable(),以拥护JLS所倡导的思想。

转载于:https://my.oschina.net/u/2291753/blog/466025

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值