zoukankan      html  css  js  c++  java
  • 注解的基本使用

    1.自定义注解类

    1 
    // 修饰符 数据类型 数据名 [默认值]
    public @interface MethodAnnotation { 2 public String[] authors(); 3 public String bookName(); 4 public double bookPrice() default 100.0;//默认注解可以不写 使用默认值 5 }

    public @interface Author {
    public String[] authors();
    }

    public @interface FailedAnnotation {
    public String[] authors();
    public String bookName();
    }

    2.注解的使用

    1 @Author(authors = {"zhangsan", "lisi", "wangwu"})//数组类型的注解
    2 public class Book {
    3     @FailedAnnotation(authors = "刘德华", bookName = "史记")//数组类型的只有一个元素可以省略{}
    4     private String name;
    5     private double price;
    6     private String[] authors;
    7     @MethodAnnotation(authors = "sima", bookName = "世纪",bookPrice = 88)//带默认值的bookPrice可以不写 如果不写就是用 default 100.0
    8     public void buyBook(){};
    9 }
  • 相关阅读:
    rabbitmqctl常用命令-3
    Count and Say
    Spiral Matrix II
    Minimum Path Sum
    Plus One
    Rotate Image
    Permutations
    Search a 2D Matrix
    Binary Tree Level Order Traversal II
    Binary Tree Level Order Traversal
  • 原文地址:https://www.cnblogs.com/MrliBlog/p/11052107.html
Copyright © 2011-2022 走看看