码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-06-12 17:36:23      阅读:228      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!