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,416
  • 8
  • 43
  • 65
snr
  • 16,197
  • 2
  • 61
  • 88

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,028
  • 28
  • 26