首页 > 其他 > 详细

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

时间:2015-06-12 17:35:28      阅读:322      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://my.oschina.net/u/2291753/blog/466025

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!