/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package java.lang.annotation;
/**
* Annotation retention policy. The constants of this enumerated type
* describe the various policies for retaining annotations. They are used
* in conjunction with the {@link Retention} meta-annotation type to specify
* how long annotations are to be retained.
*
* @author Joshua Bloch
* @since 1.5
*/
public enum RetentionPolicy {
/**
* Annotations are to be discarded by the compiler.
*/
SOURCE,
/**
* 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.
*/
CLASS,
/**
* 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 java.lang.reflect.AnnotatedElement
*/
RUNTIME
}
了解一下这个枚举的含义,
- 此枚举类型的常量描述了用于保留注解的各种策略
- 这些枚举项与
@Retention
注解一起使用,以指定注解的保留时间。
枚举项的含义:
SOURCE
:注解将被编译器丢弃CLASS
:注解将由编译器记录在类文件中,但VM不必在运行时保留它们。这是默认行为。RUNTIME
:注解将由编译器记录在类文件中,并且VM
在运行的时候也会保留,