Arun Chand Arun Chand - 11 months ago 66
Android Question

Dynamic values are not supported as attributes in annotation- AspectJ Android [AOP Android]

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();

@ArrayParams({@Params(key = "content_id",value = mAssetId)})
protected void attributeMethod() {

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.

Answer Source

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

according to the Java 5 Language Guide - Annotations.