What is the use of RetentionPolicy.CLASS and RetentionPolicy.SOURCE?

What is the estimated need for RetentionPolicy.CLASS and RetentionPolicy.SOURCE. In which annotation scenario can we use them? I needed examples.

From a Java doc:

CLASS: Annotations must be written to the class file by the compiler, but must not be saved by the VM at runtime.

  • In which scenario will we go for this as a developer?

SOURCE: annotations must be discarded by the compiler.

  • In which scenario will we go for this as a developer?
+4
source share

All Articles