I am using annotation in my java program something like this.
@annotation("some string")
public void fun(){
...
}
Is there any way that i could pass variable instead of "some string" to annotation.
e.g
String s="some string"
@annotation(s)
public void fun(){
...
}
It is not possible to give an annotation a changing variable. The value which is passed in to the annotation needs to be known at compile time.
This would work:
private final String param = "Param";
@annotation(param)
public void function() {
}
However, it must be constant and cannot be changed, e.g. intialized by the constructor. (The value in this case would be known at runtime, not compile time)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With