动态值不作为注释中的属性支持-AspectJ Android [AOP Android] [英] Dynamic values are not supported as attributes in annotation- AspectJ Android [AOP Android]
问题描述
我正在使用自定义注释来记录用户单击的ID.但是出现错误"属性值必须为常数".我的代码段如下.
I am using custom annotation to log the id which user clicked. But I am getting a error "Attribute value must be a constant". My code snippet is below.
mAssetId= Asset.getContentId();
@TrackEvent("track_event")
@ArrayParams({@Params(key = "content_id",value = mAssetId)})
protected void attributeMethod() {
}
先谢谢了.有什么方法可以在注释中传递动态值,而不是静态变量或常量.我正在为Android使用 AspectJ 库.
Thanks in advance. Is there any way to pass dynamic values in annotation rather than static variables or constants. I am using AspectJ library for android.
推荐答案
不可能在注释属性中指定运行时值,只能指定常量,甚至可能的类型集也仅限于以下几种类型:
It's not possible to specify runtime values in annotation attributes, only constants, and even the set of possible types is limited to a few types:
上述类型的基元,字符串,类,枚举,注释和数组
primitives, String, Class, enums, annotations, and arrays of the preceding types
根据 Java 5语言指南-注释.
这篇关于动态值不作为注释中的属性支持-AspectJ Android [AOP Android]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!