zoukankan      html  css  js  c++  java
  • [Java]注解

    ------------恢复内容开始------------

    内置注解:

    package Comments;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * 注解学习
     *
     * @author ZhaoLu cang on 2021/4/8 0008
     */
    public class Comments extends Object{
    
        //@Override   重写注解
        @Override
        public String toString(){
            return super.toString();
        }
    
        // Deprecated 不推荐使用,或者存在更好的方法,已经过时
        @Deprecated
        public static void deprecated(){
            System.out.println("Deprecated");
        }
    
        public static void main(String[] args) {
            deprecated();
        }
    
        //镇压警告,消除所有警告,可以加在类名上
        @SuppressWarnings("all")
        public static void suppresswarnings(){
            List list=new ArrayList();
        }
    }

    元注解:负责解释其他注解的注解

    @Target:用于描述注解的解释范围

    @Retention:用什么级别保存注解信息,source<class<runtime

    @Document::说明该注解包含在javadoc中

    @Inherited:子类可以继承父类中的注解

    package Comments;
    
    import java.lang.annotation.*;
    
    /**
     * 测试元注解
     *
     * @author ZhaoLu cang on 2021/4/8 0008
     */
    @MyAnnotation
    public class Comments02 {
    
        public void test(){
    
        }
    }
    
    //定义一个注解,Target表示我们的注解可以用在哪些地方
    @Target(value = {ElementType.METHOD,ElementType.TYPE})
    //表示注解在什么时候有效,代码source 编译后class 运行时runtime
    @Retention(value = RetentionPolicy.RUNTIME)
    //Documented 表示是否将注解生成在Javadoc中
    @Documented
    //Inherited 子类可以继承父类的注解
    @Inherited
    @interface MyAnnotation{
    
    }

    自定义注解

    @Interface自定义注解,继承了java.lang.annoctation.Annoctation

  • 相关阅读:
    strace命令的使用
    部署软件RDMA的步骤
    centos7上安装iptables
    在Linux中的.iso文件的处理方法
    centos7关闭自动锁屏
    SSH配置优化和慢的解决方法
    sort排序和uniq统计命令
    ansible的携带密码访问
    fabric入门
    防火墙设置本机端口转发
  • 原文地址:https://www.cnblogs.com/zlc364624/p/14636628.html
Copyright © 2011-2022 走看看