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:
- 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" - From reifiablity standpoint, those are different. JLS 4.6 and 4.7 codify
List<?>
as a reifiable type, butList<? 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
时间: 2024-11-09 02:17:13