Java注解与反射3-元注解
元注解
- 元注解的作用就是负责注解其他注解,Java定义了4个标准的meta-annotation类型,它们被用来提供对其他annotation类型作说明
- 这些类型和它们所支持的类在java.lang.annotation包中可以找到(@Target,@Retention,@Documented,@Inherited)
- @Target:用于描述直接的使用范围(即:被描述的直接可以用在什么地方)
- @Retention:表示需要在什么级别保存该注释信息,用于描述注解的声明周期(SOURCE<CLASS<RUNTIME)
- Document:说明该注解将被包含在javadoc中
- Inherited:说明子类可以继承父类中的该注解
package com.kuang.annotation;
import java.lang.annotation.*;
@MyAnnotation
public class Test01 {
@MyAnnotation
public void test(){
}
}
@Target(value = {ElementType.METHOD,ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
@Documented
@Inherited
@interface MyAnnotation{
}