自定义注解

package Annotation.Demo01;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public class Demo02 {
    /**自定义注解
     */

    @MyAnnotation01(age = 11)
    public void test001() {
    }

    @MyAnnotation02("fff")
    public void test002() {
    }


    @Target({ElementType.TYPE, ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @interface MyAnnotation01 {

        //注解的参数:参数类型 + 参数名();
        String name() default "";
        int age();
        int id() default -1;//如果默认值为-1,代表不存在
        String[] schools() default {"大学", "小学"};
    }


    @Target({ElementType.TYPE, ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @interface MyAnnotation02 {
        String value();

    }
}
posted @ 2022-02-24 16:23  小幼虫虫  阅读(36)  评论(0)    收藏  举报