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

  • 相关阅读:
    又一道简单的题
    atoi函数的使用(将字符串转换成整型数)
    【贪心】Radar Installation(POJ1328)
    【BFS】鸣人与佐助
    谍报分析
    适配器模式(C++实现)
    策略模式(C++)
    工厂模式(C++实现)
    桥接模式(C++实现)
    关于getMemory函数的几点思考
  • 原文地址:https://www.cnblogs.com/zlc364624/p/14636628.html
Copyright © 2011-2022 走看看