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.

java.lang.annotation.RetentionPolicy

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( )

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.