简单的java代码, 例子来自参考[1]
1 import java.util.Map; 2 import java.util.HashMap; 3 4 class Hello { 5 public static void main(String[] args) { 6 Map<String, String> map = new HashMap<String, String>(); 7 map.put("hello", "你好"); 8 map.put("how are you?", "吃了没?"); 9 System.out.println(map.get("hello")); 10 System.out.println(map.get("how are you?")); 11 } 12 }
编译后使用jd-gui进行反编译的代码
1 import java.io.PrintStream; 2 import java.util.HashMap; 3 import java.util.Map; 4 5 class Hello 6 { 7 public static void main(String[] paramArrayOfString) 8 { 9 HashMap localHashMap = new HashMap(); 10 localHashMap.put("hello", "你好"); 11 localHashMap.put("how are you?", "吃了没?"); 12 System.out.println((String)localHashMap.get("hello")); 13 System.out.println((String)localHashMap.get("how are you?")); 14 } 15 }
我们可以看出是类型擦除, 在字节码上是没有泛型的类型的, 被改为了object
参考文献:
- Java语法糖的味道:泛型与类型擦除 http://icyfenix.iteye.com/blog/1021949
- jd-gui: http://java.decompiler.free.fr/?q=jdgui