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中有一个“数组常量”这个东西......你给出的语法是一个带有运行时语义的“数组初始值设定器”。 –
什么是编译器错误信息? –