和的區別

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

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

  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"jvm

  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.this


這個解釋超牛逼,先把它記下來。它來自於http://stackoverflow.com/questions/2016017/unbounded-wildcards-in-java/2016382#2016382編碼

update:spa

如下是我翻譯的,求指點。翻譯

從使用它的角度來看,<? 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所倡導的思想。code

相關文章
相關標籤/搜索