Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass method parameter to annotation on a method?

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?

like image 257
null Avatar asked Oct 20 '22 01:10

null


1 Answers

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

like image 165
headcr4sh Avatar answered Oct 22 '22 15:10

headcr4sh