0
比方说,我们有这个法注释:是否可以将方法参数传递给方法上的注释?
@Cached(key="search" + id)
public static List<String> search(String id) {
//...
}
我想通过参数“ID”的@Cached注释的关键。
是否有可能在java中做到这一点?
比方说,我们有这个法注释:是否可以将方法参数传递给方法上的注释?
@Cached(key="search" + id)
public static List<String> search(String id) {
//...
}
我想通过参数“ID”的@Cached注释的关键。
是否有可能在java中做到这一点?
不,这是不可能的。 Java注释
属性必须是由Java语言规范定义的常量表达式(http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28)
我认为你的问题已经回答了前: Get rid of "The value for annotation attribute must be a constant expression" message
[修改类定义的注解字符串可能重复参数在运行时](http://stackoverflow.com/questions/14268981/modify-a-class-definitions-annotation-string-parameter-at-runtime) – mkrakhin 2014-09-11 11:10:02