Live2D

Java注解

注解的学习笔记

  1. 内置注解
package com.lix.annotation;

/**
 * @author lix
 */
@SuppressWarnings("all")
public class Test01 extends Object {
    //@Overide的重写
    @Override
    public String toString() {
        return super.toString();
    }
}
  1. meta-annotation(元注解)

    2.1、

    package com.lix.annotation;
    
    import org.omg.SendingContext.RunTime;
    
    import java.lang.annotation.*;
    
    /**
     * @author lix
     * 测试元注解
     */
    public class Test02 {
    
        /**
         *  @MyAnnotation(name = "lix")
         *  @MyAnnotation(age = 20,name = "lix")
         *  注解可以显示赋值,如果没有默认值,必须给注解赋值
         */
        @MyAnnotation()
        public void test() {
    
        }
        @MyAnnotation2(value = "lix")
        public void test2() {
    
        }
    }
    /**
     * @author lix
     * 自定义注解 @interface
     * @Target 表示我们的注解可以用在那些地方
     * @Retention 表示作用域   runtime>class>sources
     * @Documented 表示是否将我们的注解生成在JAVAdoc中
     * @Inherited 表示子类可以继承父类的注解
     */
    @Target(value = ElementType.METHOD)
    @Retention(value = RetentionPolicy.RUNTIME)
    @Documented
    @Inherited
    @interface MyAnnotation{
        String name() default "";
        int age() default 0;
        int id() default -1; //如果默认值为-1,代表不存在
        String[] schools() default {"北京","清华"};
    }
    /**
     * Myannotation2 description
     * @author lix
     */
    @Target(value = ElementType.METHOD)
    @Retention(value = RetentionPolicy.RUNTIME)
    @interface MyAnnotation2{
        String value();
    }
    
posted @ 2020-10-22 12:23  六爻呈乾  阅读(67)  评论(0编辑  收藏  举报