摆脱"对于标注属性的值必须是一个常量前pression"信息 [英] Get rid of "The value for annotation attribute must be a constant expression" message
问题描述
我用标注在我的code和我尝试使用它确定运行时间值。
I use annotation in my code, and I try to use value which determine in run time.
我定义我的名单静态最后
(LST),我添加到这个列表的一些元素。
I define my list as static final
(lst), and I add to this list some elements.
当我使用 lst.get(我)
,我得到的编译错误:
When I use lst.get(i)
, I get compilation error:
The value for annotation attribute must be a constant expression
,这是什么问题,该如何解决?
What is the solution for this issue?
推荐答案
有关注释的值必须是一个编译时间常数,所以做你正在尝试做的没有简单的方法。
The value for an annotation must be a compile time constant, so there is no simple way of doing what you are trying to do.
请参阅也在这里:<一href=\"http://stackoverflow.com/questions/2065937/how-to-supply-value-to-an-annotation-from-a-constant-java?rq=1\">How从恒java的提供价值注释
See also here: How to supply value to an annotation from a Constant java
有可能使用一些编译时工具(Ant,Maven的?)来配置它,如果该值知道你尝试运行程序之前。
It is possible to use some compile time tools (ant, maven?) to config it if the value is know before you try to run the program.
这篇关于摆脱&QUOT;对于标注属性的值必须是一个常量前pression&QUOT;信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!