lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey
added in API level 1

RetentionPolicy

public final enum RetentionPolicy
extends Enum<RetentionPolicy>

java.lang.Object
   ↳ java.lang.Enum<java.lang.annotation.RetentionPolicy>
     ↳ java.lang.annotation.RetentionPolicy


Annotation retention policy. The constants of this enumerated type describe the various policies for retaining annotations. They are used in conjunction with the Retention meta-annotation type to specify how long annotations are to be retained.

Summary

Enum values

RetentionPolicy  CLASS

Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. 

RetentionPolicy  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. 

RetentionPolicy  SOURCE

Annotations are to be discarded by the compiler. 

Public methods

static RetentionPolicy valueOf(String name)
static final RetentionPolicy[] values()

Inherited methods

Enum values

CLASS

added in API level 1
public static final RetentionPolicy CLASS

Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. This is the default behavior.

RUNTIME

added in API level 1
public static final RetentionPolicy 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.

See also:

SOURCE

added in API level 1
public static final RetentionPolicy SOURCE

Annotations are to be discarded by the compiler.

Public methods

valueOf

added in API level 1
public static RetentionPolicy valueOf (String name)

Parameters
name String

Returns
RetentionPolicy

values

added in API level 1
public static final RetentionPolicy[] values ()

Returns
RetentionPolicy[]