Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is happening behind @Retention in java 1.5

I am trying to understand the retention policy from Java 1.5. But not getting a clear picture.

As per JavaDoc,

  • CLASS - Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time.
  • RUNTIME - Annotations are to be recorded in the class file by the compiler and retained by the VM at run time,so they may be read reflectively.
  • SOURCE - Annotations are to be discarded by the compiler
  1. what does it mean by "discarded"?
  2. Is it like the class file will not have the particular annotated element in it by marking it with SOURCE?
like image 868
sugra Avatar asked Aug 09 '12 04:08

sugra


Video Answer


1 Answers

SOURCE annotations are only present in the source file.

When the compiler "discards" the annotation, it is essentially ignoring that the annotation even exists. Source annotations basically serve the same purpose as commenting code.

like image 185
FThompson Avatar answered Sep 21 '22 17:09

FThompson