How to pass value to custom annotation in java?

Danni Chen :

my custom annotation is:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CacheClear {

    long versionId() default 0;
}

I want to achieve something like this, in which I can pass the method param "versionTo" to my custom annotation.

@CacheClear(versionId = {versionTo})
public int importByVersionId(Long versionTo){
    ......
} 

What should I do?

Luciano van der Veekens :

That's not possible.

Annotations require constant values and a method parameter is dynamic.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=460317&siteId=1