1
public Class Constants {
public static final String single = "aabbcc";
public static final String[] ttt = {"aa", "bb", "cc"};
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD})
public @interface Anno {
String aaa() default "aaa"; //this is allowed.
String bbb() default Constants.single; //this is allowed.
String[] ccc() default {}; //this is also allowed.
String[] ddd() default Constants.ttt; //while this is not!
}
如上例所示,我不明白爲什麼字符串數組常量不允許作爲註釋屬性值?Java - 爲什麼數組常量不允許作爲Annotation屬性值?
我不相信Java中有一個「數組常量」這個東西......你給出的語法是一個帶有運行時語義的「數組初始值設定器」。 –
什麼是編譯器錯誤信息? –