I'm facing the following issue. Could any one help understand why is it so? Also please share your thoughts on making the 2nd scenario work.
This works without any compilation issues,
private final String var ="US"; @Inject @Named (var) private Validator validator;
This is giving compilation errors, Compilation Error:"The value for annotation attribute Named.value must be a constant开发者_StackOverflow expression"
private final String var =System.getProperty("US"); @Inject @Named (var) private Validator validator;
In the first case the compiler sees that a constant has been assigned to a private final variable, so it optimizes away the variable and uses the constant in its place. In the second case it can't do that, so it's left with a variable in the annotation.
精彩评论