The retention annotation indicates where and how long annotations with this type are to be retained. There are three values:
- SOURCE—Annotations with this type will be by retained only at the source level and will be ignored by the compiler.
- CLASS—Annotations with this type will be by retained by the compiler at compile time, but will be ignored by the VM.
- RUNTIME—Annotations with this type will be retained by the VM so they can be read only at run-time.
1 2 3 |
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.CLASS) |
1 2 3 4 5 6 7 8 9 |
package www.technicaljungle.com; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) public @interface RetentionAnnotationInterface { String doSomething(); } |
@Annotations