5

Let's say we have this method with annotation:

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

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

Is it possible to do this in java?

null
  • 8,669
  • 16
  • 68
  • 98
  • 1
    possible duplicate of [Modify a class definition's annotation string parameter at runtime](http://stackoverflow.com/questions/14268981/modify-a-class-definitions-annotation-string-parameter-at-runtime) – mkrakhin Sep 11 '14 at 11:10

1 Answers1

3

No. It is not possible.

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

Community
  • 1
  • 1
headcr4sh
  • 308
  • 2
  • 8