我可以调用一个在注解中返回字符串的方法吗?
如果是这样,请指导我如何实现这一目标?
Can I able to call a method which returns string inside an annotation.
If so please guide me how to achieve this?
我试过这样,但这对我不起作用.
I tried like this but this doesn't work for me.
@Description(value = Resource.getWord("key"))
注解只需要编译时常量(因为它们可能在编译时使用),因此您不能在定义中进行任何计算,因为它们在编译期间是未知的编译时间.
An annotation only takes compile time constants (as they might be used during compile time), therefore you cannot make any calculation within the definition, as they are unknown during the compile time.
允许的常量类型是(取自 java-annotation-成员):
Allowed constant types are (taken from java-annotation-members):
针对您的情况的可能解决方案:
据我了解,您希望本地化 @Description 内容.由于无论如何这只是为了向其他开发人员公开,因此在我看来,您可以安全地使用英语.本地化是针对最终用户的,而不是针对开发人员的.
As I understand you would like to localize the @Description content.
As this is only meant to be exposed to other developers anyway, you are safe to simply use English, in my opinion. Localization is for the end user, not the developer.
这篇关于在JAVA中的注释内调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)