jdk1.5起提供4个元注解(所有元注解定义在java.lang.annotation,Annotation是注解的基本接口,所有的注解都继承这个接口):
1、@Target:指定注解使用的目标范围(类、方法、字段等)ref---java.lang.annotation.ElementType(Enum);
2、@Documented:指定被标注的注解会包含在javadoc中;
3、@Retention:指定注解的生命周期(源码、class文件、运行时)ref---java.lang.annotation.RetentionPolicy;
4、@Inherited:指定子类可以继承父类的注解,只能是类上的注解;
jdk1.8又提供了以下两个元注解:
1、@Native:指定字段是一个常量;
2、@Repeatable:可以在一个地方可以重复使用同一个注解
Example:
@Retention(RetentionPolicy.RUNTIME)
@Tartget(ElementType.TYPE)
@Documented
@Repeatable(ComponentScans.class)
public @interface ComponentScans{