Java—为什么数组常量不是';不允许作为注释属性值?

Java—为什么数组常量不是';不允许作为注释属性值?,java,annotations,Java,Annotations,正如上面所示的例子,我不明白为什么字符串数组常量不允许作为注释属性值?就像Jim Garrison在评论中提到的那样,Java中没有“数组常量”这样的东西 很容易证明数组不是常数: public Class Constants { public static final String single = "aabbcc"; public static final String[] ttt = {"aa", "bb", "cc"}; } @Retention(RetentionPo

正如上面所示的例子,我不明白为什么字符串数组常量不允许作为注释属性值?

就像Jim Garrison在评论中提到的那样,Java中没有“数组常量”这样的东西

很容易证明数组不是常数:

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中没有字符串数组常量。

我不相信Java中有“数组常量”这样的东西。。。您给出的语法是具有运行时语义的“数组初始值设定项”。编译器错误消息是什么?
// Right now, Constants.ttt contains {"aa", "bb", "cc"}
Constants.ttt[1] = "foobar";
// Right now, Constants.ttt contains {"aa", "foobar", "cc"}