Java - Error: Attribute value must be constant

时间:2015-02-08 00:29:12   收藏:0   阅读:8610

Error: Attribute value must be constant


本文地址:http://blog.csdn.net/caroline_wendy

Attribute value must be constant. 属性的值必须要是Constant. 
如,在Annotation的接口中的值,但是字符串数组不能指定为Constant,Java中static final
只能把纯字符设置为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() {
        }
    }
数组无法进行常量化,只能使用字符常量。

参考: http://stackoverflow.com/questions/2065937/how-to-supply-value-to-an-annotation-from-a-constant-java


技术分享

原文:http://blog.csdn.net/caroline_wendy/article/details/43614547

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!