java注解和反射-- 元注解

元注解用于

创建注解的注解

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{
    
    

}

猜你喜欢

转载自blog.csdn.net/qq_43619461/article/details/120978272