我在代码中使用注释,并尝试使用在运行时确定的值.
我将我的列表定义为static final(lst),并在此列表中添加一些元素.
当我使用时lst.get(i),我得到编译错误:
The value for annotation attribute must be a constant expression
Run Code Online (Sandbox Code Playgroud)
这个问题的解决方案是什么?
想象一下有一节课:
@Something(someProperty = "some value")
public class Foobar {
//...
}
Run Code Online (Sandbox Code Playgroud)
哪个已编译(我无法控制源),并且是jvm启动时类路径的一部分.我希望能够在运行时将"某些值"更改为其他内容,这样之后的任何反射都将具有我的新值而不是默认的"某个值".
这可能吗?如果是这样,怎么样?