注解概述

package com_annotation;

/**
 * FileName: AnnotationDemo01
 * Author:   lps
 * Date:     2022/4/23 11:44
 * Sign:刘品水 Q:1944900433
 * 注解的作用:对java中类、方法、成员变量做标记,然后进行特殊处理
 * public @interface 注解名称{
 * public 属性类型 属性名()default 默认值;
 * }
 * 元注解有两个:@Target约束自定义注解只能在哪些地方使用 @Retention:申明注解的生命周期
 */
@MyBook(name = "《Java基础》", authors = {"刘品水", "鸡汤哥"}, prices = 19.99)
//@Book(value = "/delete")
//@Book(value = "/delete",price = 22.22)
@Book("/delete")
public class AnnotationDemo01 {
    @MyBook(name = "《Java基础》", authors = {"刘品水", "鸡汤哥"}, prices = 19.99)
    private AnnotationDemo01() {
    }

    @MyBook(name = "《Java基础》", authors = {"刘品水", "鸡汤哥"}, prices = 19.99)
    public static void main(String[] args) {

    }
}
package com_annotation;

/**
 * FileName: AnnotationDemo02
 * Author:   lps
 * Date:     2022/4/23 12:11
 * Sign:刘品水 Q:1944900433
 * 元注解有两个:
 * @Target约束自定义注解只能在哪些地方使用
 * @Retention:申明注解的生命周期
 */

public class AnnotationDemo02 {
    @MyTest
    private String name;

    @MyTest
    public void test() {
    }


    public static void main(String[] args) {

    }
}
package com_annotation;

/**
 * FileName: Book
 * Author:   lps
 * Date:     2022/4/23 11:58
 * Sign:刘品水 Q:1944900433
 * @author lps
 */
public @interface Book {
 String value();//特殊属性
 double price() default 18.88;

}
package com_annotation;

/**
 * FileName: MyBook
 * Author:   lps
 * Date:     2022/4/23 11:48
 * Sign:刘品水 Q:1944900433
 * @author lps
 */
public @interface MyBook {
    String name();
    String[] authors();
    double prices();


}
package com_annotation;

/**
 * FileName: MyBook
 * Author:   lps
 * Date:     2022/4/23 11:48
 * Sign:刘品水 Q:1944900433
 * @author lps
 */
public @interface MyBook {
    String name();
    String[] authors();
    double prices();


}

 

posted @ 2022-04-23 13:27  刘品水  阅读(20)  评论(0编辑  收藏  举报