ElementType.LOCAL_VARIABLE annotation type

前端 未结 4 697
一生所求
一生所求 2020-12-11 01:45

I`d like to create my own annotations to annotate some local variable. To write the annotation is not the problem, the problem is to get the information of them at the Runti

4条回答
  •  无人及你
    2020-12-11 01:54

    As of Java 8, local variable annotations are retained in class files. As noted by Erick Hagstrom, this long-standing bug was fixed by JSR 308, which also added type annotations to the Java language.

    However, Java's reflection API has not been updated to give access within method bodies. You will need to parse the classfile yourself. You can use a tool such as ASM. EDIT: I don't recommend JavaParser, because it has not been updated beyond Java 1.5. JavaParser has been updated.

提交回复
热议问题