java中元注解有四个: @Retention @Target @Document @Inherited;
@Retention:注解的保留位置
@Retention(RetentionPolicy.SOURCE) //注解仅存在于源码中,在class字节码文件中不包含
@Retention(RetentionPolicy.CLASS) // 默认的保留策略,注解会在class字节码文件中存在,但运行时无法获得,
@Retention(RetentionPolicy.RUNTIME) // 注解会在class字节码文件中存在,在运行时可以通过反射获取到
@Target:注解的作用目标
@Target 注解一般跟一个注解使用的目标位置,所有 Target 在注解 中指定
public enum ElementType {
/** Class, interface (including annotation type), or enum declaration */
TYPE,// 接口、类、枚举
/** Field declaration (includes enum constants) */
FIELD,//字段、枚举的常量
/** Method declaration */
METHOD,//方法
/** Formal parameter declaration */
PARAMETER, //方法参数
/** Constructor declaration */
CONSTRUCTOR, //构造函数
/** Local variable declaration */
LOCAL_VARIABLE,//局部变量
/** Annotation type declaration */
ANNOTATION_TYPE,//注解
/** Package declaration */
PACKAGE,//包
/**
* Type parameter declaration
*
* @since 1.8
*/
TYPE_PARAMETER, // 方法参数
/**
* Use of a type
*
* @since 1.8
*/
TYPE_USE
}
@Document:说明该注解将被包含在javadoc中
@Inherited:说明子类可以继承父类中的该注解
参考:https://blog.csdn.net/sw5131899/article/details/54947192