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)
// .
// .
kryger
  • 12,906
  • 8
  • 44
  • 65

1 Answers1

4

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

user268396
  • 11,576
  • 2
  • 31
  • 26