可以在运行时确定注释变量吗? [英] Can the annotation variables be determined at runtime?

查看:30
本文介绍了可以在运行时确定注释变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在运行时设置注解变量?

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

推荐答案

不,这不可能.

注解作为常量值存储在类文件中,不能在运行时计算.

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.

例如,您可以用某种脚本语言存储一个简单的表达式,并在读取注释值时执行该表达式,或者您可以指定要调用的方法名称以获取实际值.这种语言的一个例子是 Spring 表达式Spring 中使用的语言 (SpEL).

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.

这篇关于可以在运行时确定注释变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆