注解Retention和Target

Java元注解:
@Target
@Retention
@Documented
@Inherited

@Target描述注解的使用范围,取值如下:
Elementtype.CONSTRUCTOR:描述构造器
ElementType.FIELD:描述成员变量
ElementType.VARIABLE:描述局部变量
ElementType.METHOD:描述方法
ElementType.PACKAGE:描述包
ElementType.PARAMETER:描述方法的参数
ElementType.TYPE:描述类、接口、或枚举类型

@Retention注解的声明周期,即在什么级别保留,取值
RetentionPoicy.SOURCE:在源文件中有效
RetentionPoicy.CLASS:在class文件中有效

猜你喜欢

转载自blog.csdn.net/weixin_34301307/article/details/86961780