I am wondering whether I can set the annotation variable in the runtime?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With