I have enum:
public enum Scope {
USER, GLOBAL;
public static final Scope[] TRANSIENT = {};
public static final Scope[] USER_OVER_GLOBAL = {GLOBAL, USER};
public static final Scope[] GLOBAL_OVER_USER = {USER, GLOBAL};
}
and annotation:
public @interface Config {
public Scope[] load() default Scope.GLOBAL_OVER_USER; // Can't use this defval
public Scope[] save() default Scope.USER;
}
Why I can’t use static arrays as default values for annotation’s property? My NetBeans 7.3 Beta tell me there is required Scope but found Scope[] – as you can see this not true. Is there a NB’s or Java 7 related confusion?
The problem is that the
Scope[] GLOBAL_OVER_USERis not all constant. (Yes, the array itself is constant, however you can change the contents of it e.g.GLOBAL_OVER_USER[0] = GLOBAL;.A workaround is to initiate the array directly in the annotation declaration: