自定义注解
1. 元注解
元注解:用于修饰注解。
四种元注解:
① @Retention: 只能用于修饰一个 Annotation 定义, 用于指定该 Annotation 的生命周期, @Rentention 包含一个 RetentionPolicy 类型的成员变量。
**RetentionPolicy.SOURCE:**在源文件中有效;
RetentionPolicy.CLASS:在class文件中有效;
RetentionPolicy.RUNTIME:在运行时有效;
②@Target: 用于修饰 Annotation 定义, 用于指定被修饰的 Annotation 能用于修饰哪些程序元素。我的理解是可以在哪里使用这个注解。
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 */