我们可以在运行时设置Annotation id

时间:2017-02-06 05:13:49

标签: java

有没有办法在注释方法中设置id ...

注释类:

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public
@interface MyAnnotation {
    int id();
}

//Set id at runtime
public class A {
    @MyAnnotation(id = ? )
    public void method1() {
        // I want to set the id here for my annotation...

    }

}

1 个答案:

答案 0 :(得分:0)

是的,但这有点不直观。您必须使用JavaAssist之类的工具编辑其字节码。

这是一个描述你所追求的article

相关问题