zoukankan      html  css  js  c++  java
  • Java:泛型在编译时会被檫除,Eclipse 如何给出智能提示?

    背景

    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 识别。

  • 相关阅读:
    让Flask-admin支持markdown编辑器
    单例模式
    【Python】关于如何判断一个list是否为空的思考
    【Python】抽象工厂模式
    【Python篇】工厂模式
    【Python】直接赋值,深拷贝和浅拷贝
    【Python】可变对象和不可变对象
    【Python】__name__ 是什么?
    【Python】any() 或者 or
    [Python] list vs tupple
  • 原文地址:https://www.cnblogs.com/happyframework/p/3377920.html
Copyright © 2011-2022 走看看