1

The Javadoc says:

Runtime: Annotations are to be recorded in the class file by the compiler and retained by the VM at runtime, so they may be read reflectively.

Class: Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at runtime

Source: Annotations are to be discarded by the compiler.

I do not understand the practical usage of Source and Class? Could anyone please clarify.?

Zabuzard
  • 25,064
  • 8
  • 58
  • 82
nam din
  • 11
  • 1
  • The enum lists different operation modes that describe how the JVM/compiler should deal with annotations. You can probably change the behavior using commands to the JVM at startup (I'm no expert on this). The default behavior seems to be `CLASS` (see current Java 9 [documentation](https://docs.oracle.com/javase/9/docs/api/java/lang/annotation/RetentionPolicy.html#SOURCE)). What exactly is unclear to you? `RUNTIME` means annotations must be kept. `Source` means they must be discarded and `Class` is something in between (VM may discard it but class files must keep it). – Zabuzard Feb 09 '18 at 00:24
  • 1
    It is simply to reduce the size of the resulting bytecode. There is no benefit from having hundreds of annotations in the final code if the annotation is only relevant for the compiler or a source-code analyze tool. For example is an `@Override` annotation not relevant to the JVM, only to the compiler. Or something like `@Non-Null` from some tools or IDEs. – Zabuzard Feb 09 '18 at 00:35

0 Answers0