Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing value to custom annotation in java

I am using custom annotation with aspectj.

@TestLoggingAnnotation(setMessage = "I want to set value here")
public void get() {

    String retString = null;
    String message = "DEFAULT";

    if (message == "DEFAULT") {

        retString = "Default Logging";

    } else {

        retString = "Custom Logging";
    }
}

The above is just simple and sample code. My requirement is that I want to pass the parameter value after resulting from method.

In my case I want set retString value to setMessage in custom parameter.

like image 733
Shahid Ghafoor Avatar asked Oct 10 '13 12:10

Shahid Ghafoor


1 Answers

As of now, annotations can only take compile constants and cant be assigned values at runtime, though their value can be used at runtime using @Retention.

discussion follows here

like image 54
codingenious Avatar answered Oct 02 '22 09:10

codingenious