Stay organized with collections
Save and categorize content based on your preferences.
RetentionPolicy
class RetentionPolicy
Known Direct Subclasses
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.
|
|
Annotation retention policy. The constants of this enumerated class describe the various policies for retaining annotations. They are used in conjunction with the Retention
meta-annotation interface to specify how long annotations are to be retained.
Summary
Enum values |
Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time.
|
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.
|
Annotations are to be discarded by the compiler.
|
Enum values
CLASS
enum val CLASS : RetentionPolicy
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
enum val RUNTIME : RetentionPolicy
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.
SOURCE
enum val SOURCE : RetentionPolicy
Annotations are to be discarded by the compiler.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# RetentionPolicy\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nRetentionPolicy\n===============\n\n```\nclass RetentionPolicy\n```\n\n|---|---|-------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||\n| ↳ | [kotlin.Enum](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-enum/index.html)\\\u003c[java.lang.annotation.RetentionPolicy](#)\\\u003e ||\n| | ↳ | [java.lang.annotation.RetentionPolicy](#) |\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [RetentionPolicy.CLASS](#ENUM_VALUE:CLASS), [RetentionPolicy.RUNTIME](#ENUM_VALUE:RUNTIME), [RetentionPolicy.SOURCE](#ENUM_VALUE:SOURCE) |------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------| | [RetentionPolicy.CLASS](#ENUM_VALUE: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](#ENUM_VALUE: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](#ENUM_VALUE:SOURCE) | Annotations are to be discarded by the compiler. | |\n\nAnnotation retention policy. The constants of this enumerated class describe the various policies for retaining annotations. They are used in conjunction with the [Retention](/reference/kotlin/java/lang/annotation/Retention) meta-annotation interface to specify how long annotations are to be retained.\n\nSummary\n-------\n\n| Enum values ||\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [CLASS](#ENUM_VALUE:CLASS) Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. |\n| [RUNTIME](#ENUM_VALUE: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. |\n| [SOURCE](#ENUM_VALUE:SOURCE) Annotations are to be discarded by the compiler. |\n\nEnum values\n-----------\n\n### CLASS\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val CLASS : RetentionPolicy\n```\n\nAnnotations 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. \n\n### RUNTIME\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val RUNTIME : RetentionPolicy\n```\n\nAnnotations 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. \n**See Also**\n\n- [java.lang.reflect.AnnotatedElement](../reflect/AnnotatedElement.html#) \n\n### SOURCE\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val SOURCE : RetentionPolicy\n```\n\nAnnotations are to be discarded by the compiler."]]