其他分享
首页 > 其他分享> > 元注解

元注解

作者:互联网

元注解 : 注解在注解上的注解

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Component {

String value() default "";

}

@Target (靶)

通过ElementType枚举选择

@Retention (保留)

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, //在class文件时保留, 在加载到VM时会被丢弃,即只在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 //会被加载进到VM, VM中通过反射是可以获取到此注解
}

@Inherited (遗传)

注意 :

@Documented

参考 :
https://blog.csdn.net/qq_43390895/article/details/100175330

标签:Target,VM,RetentionPolicy,Inherited,注解,RUNTIME
来源: https://www.cnblogs.com/wftop1/p/14770005.html