Java - Error: Attribute value must be constant

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

时间: 2024-10-06 15:09:09

Java - Error: Attribute value must be constant的相关文章

error RC2108: expected numerical dialog constant

转载自:http://blog.csdn.net/renyhui/article/details/23120469 在我们用图形控件Picture Control在对话框上添加图片是,经常会出现error RC2108: expected numerical dialog constant 解决方法: 双击error rc2018...打开文件 在如图所示的位置增加"Static", SS_BITMAP

Scala Java Error: value filter is not a member of *

错误字符串 Scala Java Error: value filter is not a member of * 解决办法 在代码中引入下面名字空间 import collection.JavaConversions._

MFC出现 error RC2108: expected numerical dialog constant错误解决办法

MFC在使用picture console控件之后往往会弹出这个错误:error RC2108: expected numerical dialog constant. 此时,双击这个错误,会跳到提示错误的那一行,在那一行中的一串地址前插入:"Static", SS_BITMAP,

springboot+RabbitMQ 问题 RabbitListener 动态队列名称:Attribute value must be constant

因为多机环境fanout广播模式,每台机器需要使用自己的队列接受消息 所以尝试使用以下的方案 private static final String QUEUE_NAME="foo."+IPUtils.getLocalhostIp(); @RabbitListener(queues = QUEUE_NAME) public void process(String command){ ... } but...果断报错:Attribute value must be constant 解决

Java Error: Failed to validate certificate. The application will not be executed

Hi, last week a customer had the problem that he wants to connect to the administration interface of a Brocade FC Switch but the Java Applet did not start. This error message was shown: "Failed to validate certificate. The application will not be exe

Java Error和Exception区别

Error和Exception都继承自Throwable: 二者不同之处: Exception: 1.可以是可被控制(checked)或者不可控制(unchecked): 2.表示一个由程序员导致的错误: 3.应该在应用程序级被处理: Error: 1.总是不可控制的(unchecked): 2.经常用来表示系统错误或者底层资源错误: 3.如果可能的话,应该在系统级被捕捉: Java 中定义了两类异常: 1) Checked exception: 这类异常都是Exception的子类.异常的向上

Java Error(三)

如下图所示Source Code : public class Test{ public static void main(String[]args){ String s = "Google"; char []a = {'a','b','c'}; StringBuffer s1 = new StringBuffer(s); s1.append('/').append("IBM").append('/').append("Sun"); System

Java Error(六)

Collection Sort .binarySearch Warning : import java.util.*; public class ListInterface2 { public static void main(String []args){ List L1 = new LinkedList(); List L2 = new LinkedList(); for(int i=0; i<=10; i++) { L2.add("b" + i); } for(int i=

butterknife异常提示:attribute value must be constant

就是因为你的android工程师lib的 如: apply plugin: 'com.android.library' android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyE