I want to provide annotations with some values generated by some methods.
I tried this so far:
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();
}
}
Thought GENERIC_GENERATED_NAME
is static final
, it complains that
The value for annotation attribute
MyInterface.aString
must be a constant expression
So how to achieve this ?