Can the annotation variables be determined at 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.

Leave a Comment