我想为某些方法生成的某些值提供注释.
到目前为止我已经试过了
public @interface MyInterface { String aString(); }
@MyInterface(aString = MyClass.GENERIC_GENERATED_NAME) public class MyClass { static final String GENERIC_GENERATED_NAME = MyClass.generateName(MyClass.class); public static final String generateName(final Class<?> c) { return c.getClass().getName(); } }
思想GENERIC_GENERATED_NAME是静态的最后,它抱怨
The value for annotation attribute
MyInterface.aString
must be a constant expression
那么如何实现呢?