0

I come up with a idea that passing a String literal to annotation. Is it possible in Java 8/9? If not, in what circumstances could it be needed? How can it be applied otherwise?

For example:

final String test = "literal";

@Component(test)
// .
// .

1 Answer 1

5

It has to be compile time constant. A public static final String will work, a merely final one won't (the enclosing scope/class means it's not compile time constant).

See also this Q/A: Compile time constants and variables

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.