Nov 8, 2018

@Retention Java Annotation

@Retention is one of the built-In Annotations that are used for ‘Annotating an Annotation’.

@Retention indicates how long annotations whose annotated types are annotated @Retention are to be retained.
The value of @Retention can be one of the members of the java.lang.annotation.RetentionPolicy enum:

  1. SOURCE. Annotations are to be discarded by the Java compiler.
  2. CLASS. Annotations are to be recorded in the class file but not be retained by the JVM. This is the default value.
  3. RUNTIME. Annotations are to be retained by the JVM so you can query them using reflection.
See also:

@Target Java Annotation