0

I have read Thinking in Java in which I know AnnotationProcessor use Reflection to resolve annotation.

After I dive into the source, I know this annotation's Retention Policy is Source. So I think maybe there's a Processor which get the String like "unused" to make IDE's linting suppress the warning.

But I don't know whether I'm right and if not how's that works?

Thanks a lot, I'm kind of newbie.

jojo_007
  • 115
  • 1
  • 5
  • `@SuppressWarnings` may be special in that it's handled directly by the compiler, rather than through an actual annotation processor. Please note, however, that I have no basis for that conjecture. – Slaw Nov 02 '19 at 14:59

1 Answers1

2

Normally, an annotation processor does not use Reflection, as it is intended to be used at compile-time. Instead, it receives an abstraction of the compiler’s model of the source code, see the java.compiler module for details.

However, since the support for the @SuppressWarnings annotation is mandated by the language specification, it is unlikely to ship with the compiler in the shape of an external annotation processor. Instead, the support will be directly built into the compiler itself.

Otherwise, the compiler needed to provide an additional API for controlling the warnings, just to provide an annotation processor taking the values of the annotation and feeding them back into the additional API. That would be an unnecessary complication with no additional value.

Holger
  • 285,553
  • 42
  • 434
  • 765