Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the annotation variables be determined at runtime?

I am wondering whether I can set the annotation variable in the runtime?

like image 267
user705414 Avatar asked Apr 21 '11 10:04

user705414


1 Answers

No, that's not possible.

Annotations are stored in the class file as constant values and can't be computed at runtime.

The best you can do is store some kind of "instructions" on how to compute the value.

For example you could store a simple expression in some scripting language and execute that when reading the annotation value or you could specify the name of a method to call to get the real value. One example of such a langauge is the Spring Expression Language (SpEL) used in Spring.

like image 113
Joachim Sauer Avatar answered Oct 24 '22 01:10

Joachim Sauer