是否可以将方法参数传递给方法上的注释? [英] Is it possible to pass method parameter to annotation on a method?
本文介绍了是否可以将方法参数传递给方法上的注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我们有这个带有注解的方法:
Let's say we have this method with annotation:
@Cached(key="search" + id)
public static List<String> search(String id) {
//...
}
我想将参数id"传递给@Cached 注释的键.
I want to pass parameter "id" to the @Cached annotation's key.
可以在java中做到这一点吗?
Is it possible to do this in java?
推荐答案
没有.这是不可能的.
Java 注释的属性必须是 Java 语言规范中定义的常量表达式 (http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28)
Attributes of Java Annotations must be constant expressions as defined by the Java Language Specification (http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28)
我认为您的问题之前已经得到解答:摆脱"注解属性的值必须是一个常量表达式"留言
I think your question has been answered before: Get rid of "The value for annotation attribute must be a constant expression" message
这篇关于是否可以将方法参数传递给方法上的注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文