java注解和反射– 元注解

java
Author

dd21

Published

December 5, 2022

元注解用于

创建注解的注解

package cn.usts.edu.InnerAnnotation;


import java.lang.annotation.*;

/**
 * 元注解
 * 用于创建注解的注解
 * */

@MyAnnotation
public class OriginAnnotation {
    @MyAnnotation
    public void test(){
    }
}

// 定义一个注解
//@Target(value = ElementType.METHOD) // 只能在方法上生效
@Target(value = { ElementType.METHOD, ElementType.TYPE}) // 在方法和类上都生效
@Retention(value = RetentionPolicy.RUNTIME)//表示我们的注解在什么地方还有效   通常自己写的都是runtime   runtime>class>sources
@Documented() // 是否将我们的注解加入到javaDoc中
@Inherited // 子类可继承父类的注解
    
@interface MyAnnotation{

}