元注解
用于注解其他注解类的注解
@Retention
@Target
@Documented
@Inherited
@Retention
@Retention,保留级别设定
SOURCE:源代码级,不会编译到class文件
Class:会被编译到class文件中,但加载时忽略
Runtime:会被编译到class文件中,并被加载到JVM
显然,框架设计中要从class文件中提取注解,所以在反射中必须使用RUNTIME级别
@Target
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target({ TYPE, FIELD, METHOD })
public @interface Example
{
}