zoukankan      html  css  js  c++  java
  • 自定义注解

    自定义注解

    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    
    //自定义注解
    public class Test03 {
        //注解可以显示赋值,如果没有默认值,我们就必须给注解赋值
        @MyAnnotation2(age = 18,name = "Lu")
        public void test(){}
    
        @MyAnnotation3("Lu")
        public void test2(){}
    
    }
    
    @Target({ElementType.TYPE,ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @interface MyAnnotation2{
    
        //注解的参数:参数类型 + 参数名(); 此处不是方法
        String name() default "";
        int age() default 0;
        int id() default -1; //如果默认值为-1,代表不存在,indexof,如果找不到就返回-1
    
        String[] schools() default {"西部开源","清华大学"};
    }
    
    @Target({ElementType.TYPE,ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @interface MyAnnotation3{
        //value可以默认在main中不写
        String value();
    }
    
  • 相关阅读:
    ASP.NET连接各种数据库办法
    随机生成中文验证码
    数据库进阶
    mysql数据库
    shell 系统学习
    redis 常见问题
    Linux下Nginx服务Rewrite和Proxy_Pass
    python 开发之路(2)
    shell 基础及提高
    mysql数据库和表物理内存
  • 原文地址:https://www.cnblogs.com/helloxiaolu/p/13325294.html
Copyright © 2011-2022 走看看