背景
Java 的泛型是一种语法糖,编译时会被“檫除”,参考文章:http://docs.oracle.com/javase/tutorial/java/generics/,如果没有源代码,Eclipse 如何给出智能提示?
Eclipse 如何给出智能提示?
测试泛型类
1 package springstudy.aop; 2 3 public class GenericTest<T> { 4 public void test(T t) { 5 } 6 }
编译后的 class
1 // Compiled from GenericTest.java (version 1.7 : 51.0, super bit) 2 // Signature: <T:Ljava/lang/Object;>Ljava/lang/Object; 3 public class springstudy.aop.GenericTest { 4 5 // Method descriptor #6 ()V 6 // Stack: 1, Locals: 1 7 public GenericTest(); 8 0 aload_0 [this] 9 1 invokespecial java.lang.Object() [8] 10 4 return 11 Line numbers: 12 [pc: 0, line: 3] 13 Local variable table: 14 [pc: 0, pc: 5] local: this index: 0 type: springstudy.aop.GenericTest 15 Local variable type table: 16 [pc: 0, pc: 5] local: this index: 0 type: springstudy.aop.GenericTest<T> 17 18 // Method descriptor #17 (Ljava/lang/Object;)V 19 // Signature: (TT;)V 20 // Stack: 0, Locals: 2 21 public void test(java.lang.Object t); 22 0 return 23 Line numbers: 24 [pc: 0, line: 5] 25 Local variable table: 26 [pc: 0, pc: 1] local: this index: 0 type: springstudy.aop.GenericTest 27 [pc: 0, pc: 1] local: t index: 1 type: java.lang.Object 28 Local variable type table: 29 [pc: 0, pc: 1] local: this index: 0 type: springstudy.aop.GenericTest<T> 30 [pc: 0, pc: 1] local: t index: 1 type: T 31 }
说明
虽然泛型参数被檫除了,但是会自动生成一些“注释”,这些注释可以被 Eclipse 识别。