Java - Error: Attribute value must be constant
Error: Attribute value must be constant
本文地址:http://blog..net/caroline_wendy 本文地址:http://blog..net/caroline_wendy
Attribute value must be constant. 属性的值必须要是Constant. Attribute value must be constant. 属性的值必须要是Constant.
如,在
Annotation的接口中的值,但是字符串数组不能指定为Constant,Java中
static final。 如,在 Annotation的接口中的值,但是字符串数组不能指定为Constant,Java中 static final。
只能把纯字符设置为
Constant,因此只能按如下使用: 只能把纯字符设置为 Constant,因此只能按如下使用:
public @interface SampleAnnotation {
String[] sampleValues();
}
public class Values {
public static final String v1 = "A";
public static final String v2 = "B";
@SampleAnnotation(sampleValues = { v1, v2 })
public void foo() {
}
} 数组无法进行常量化,只能使用字符常量。 public @interface SampleAnnotation { String[] sampleValues(); } public class Values { public static final String v1 = "A"; public static final String v2 = "B"; @SampleAnnotation(sampleValues = { v1, v2 }) public void foo() { } } 数组无法进行常量化,只能使用字符常量。
参考: 参考:
