I have a class that defines a bunch of things, i.e., target names and arrays of parameters:
public class Actions {
protected static final String A_TARGET = "do_a";
protected static final String[] A_ARGS = { "paramA", "paramB" };
...
}
I am trying to write a custom annotation to avoid action registration in a constructor, so I have defined:
public @interface MyAnno{
String actionTarget();
String[] actionArgs();
}
And am trying to use it as such:
@MyAnno(
actionTarget = Actions.A_TARGET,
actionArgs = Actions.A_ARGS <-- compile error
)
public void doA() {
}
I am however experiencing an issue with the marked line, an issue with passing in the String array of arguments to the annotation:
The value for annotation attribute MyAnno.A_ARGS must be an array initializer
If I replace Actions.A_ARGS
with the array I have defined in my Actions
class, { "paramA", "paramB" }
, the error goes away...
My question is:
How can I go about having this args array defined elsewhere, and then using it in the Annotation?