Java注解机制分析
2017-12-05 00:00
134 查看
摘要: Java 注解 annotation
Java注解在很多地方被用到,在此对其进行分析并记录,以期能更深入的理解注解。
Target,如下:
RetentionPolicy有三个:如下
Java注解在很多地方被用到,在此对其进行分析并记录,以期能更深入的理解注解。
Target,如下:
package java.lang.annotation; /** * A program element type. The constants of this enumerated type * provide a simple classification of the declared elements in a * Java program. * * <p>These constants are used with the {@link Target} meta-annotation type * to specify where it is legal to use an annotation type. * * @author Joshua Bloch * @since 1.5 */ public enum ElementType { /** Class, interface (including annotation type), or enum declaration */ TYPE, /** Field declaration (includes enum constants) */ FIELD, /** Method declaration */ METHOD, /** Parameter declaration */ PARAMETER, /** Constructor declaration */ CONSTRUCTOR, /** Local variable declaration */ LOCAL_VARIABLE, /** Annotation type declaration */ ANNOTATION_TYPE, /** Package declaration */ PACKAGE }
RetentionPolicy有三个:如下
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 }
相关文章推荐
- JAVA 注解机制及其原理
- Java的注解机制——Spring自动装配的实现原理
- 深入分析Java线程中断机制
- Java ClassLoader机制分析
- Java 动态代理机制分析及扩展,第 1 部分
- 深入分析 Java I/O 的工作机制
- 全面分析Java的垃圾回收机制
- Android系统进程间通信Binder机制在应用程序框架层的Java接口源代码分析
- Java 动态代理机制分析及扩展
- 深入分析 Java I/O 的工作机制
- Java的注解机制——Spring自动装配的实现原理
- JAVA垃圾回收机制分析
- 深入分析 Java I/O 的工作机制
- Java回调机制分析
- 详细深入分析 Java ClassLoader 工作机制
- 深入理解Java注解(含案例分析)
- java异常机制分析
- Java 动态代理机制分析及扩展,第 2 部分
- Java注解分析以及自定义注解
- [JAVA基础系列]java程序的运行机制分析