package annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
// meta-annotation 元注解
// 元注解的作用就是负责注解其他注解,意思就是解释其他注解
//第一个:@Target:用于描述注解的使用范围,就是说这个注解可以使用在什么地方
//第二个:@Retention:表示在什么时候还有效,用于描述注解的生命周期,(source<class<runtime)一般都是定义runtime,runtime表示在运行时有效
//第三:@Document:表示是否将我们的注解生成在javaDoc中
//第四:@Inherited:表示子类可以继承父类注解
public class MetaAnnotation {
@MyAnnotation //因为元注解Target定义了@MyAnnotation可以用在方法中,所以此处正确不报错
public void test(){
}
}
//注意:一个类中只能有一个public修饰类,但在public修饰的类中,可以用public修饰方法等
//定义一个注解
//@Target(value = ElementType.METHOD)//表示只可以在方法中使用
@Target({ElementType.TYPE,ElementType.METHOD})//表示可以在类和方法中有效
@Retention(value = RetentionPolicy.RUNTIME)//表示MyAnnotation这个注解在运行时还有效
@interface MyAnnotation{
}