Name
RetentionPolicy
Synopsis
The
constants
declared by the enumerated type specify the possible retention values
for an @Retention meta-annotation. Annotations
with SOURCE retention appear in Java source code
only and are discarded by the compiler. Annotations with
CLASS retention are compiled into the class file
and are visible to tools that read class files but are not loaded by
the Java VM at runtime. (This is the default retention for annotation
types that do not have an @Retention
meta-annotation.) Finally, annotations with
RUNTIME retention are stored in the class file and
loaded by the Java interpreter at runtime. These annotations are
available for reflective access through
java.lang.reflect.AnnotatedElement.
Figure 10-81. java.lang.annotation.RetentionPolicy
public enum RetentionPolicy { // Enumerated Constants SOURCE, CLASS, RUNTIME; // Public Class Methods public static RetentionPolicy valueOf(String name); public static final RetentionPolicy[ ] values( ); }
Returned By
Retention.value( )
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access