是否可以将方法参数传递给方法的注释?

问题描述:

比方说,我们有这种带有注释的方法:

Let's say we have this method with annotation:

@Cached(key="search" + id)
public static List<String> search(String id) {
    //...
}

我想将参数"id"传递给@Cached批注的键.

I want to pass parameter "id" to the @Cached annotation's key.

是否可以在Java中执行此操作?

Is it possible to do this in java?

否.这是不可能的.

Java注释的属性必须是Java语言规范(

Attributes of Java Annotations must be constant expressions as defined by the Java Language Specification (http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28)

我认为您的问题之前已经得到回答: 摆脱";批注属性的值必须是一个常量表达式消息

I think your question has been answered before: Get rid of "The value for annotation attribute must be a constant expression" message