zoukankan      html  css  js  c++  java
  • 元注解(注解的注解)

    元注解(注解的注解)

      a. @Retention 
       它是被定义在一个注解类的前面,用来说明该注解的生命周期。
       它有以下参数: 
          RetentionPolicy.SOURCE:指定注解只保留在源文件当中。
          RetentionPolicy.CLASS:指定注解只保留在class文件中。(缺省)
          RetentionPolicy.RUNTIME:指定注解可以保留在程序运行期间。
       b. @Target 
       它是被定义在一个注解类的前面,用来说明该注解可以被声明在哪些元素前。(默认可以放在任何元素之前)
       它有以下参数: 
        ElementType.TYPE:说明该注解只能被声明在一个类、接口、枚举前。 
        ElementType.FIELD:说明该注解只能被声明在一个类的字段前。
        ElementType.METHOD:说明该注解只能被声明在一个类的方法前。
        ElementType.PARAMETER:说明该注解只能被声明在一个方法参数前。 
        ElementType.CONSTRUCTOR:说明该注解只能声明在一个类的构造方法前。
        ElementType.LOCAL_VARIABLE:说明该注解只能声明在一个局部变量前。
        ElementType.ANNOTATION_TYPE:说明该注解只能声明在一个注解类型前。
        ElementType.PACKAGE:说明该注解只能声明在一个包名前。

      c. @Inherited 表明该注解将会被子类继承。

         需要说明的是,加上该元注解的注解,只有用在类元素上才有效果。这是在JDK总的原话:

        Note that this meta-annotation type has no effect if the annotated
        type is used to annotate anything other than a class. Note also
        that this meta-annotation only causes annotations to be inherited
        from superclasses; annotations on implemented interfaces have no
        effect

        但是在其他元素上的注解,只要你没有覆盖父类中的元素,是会继承过来的。这就是为什么有getDeclaredAnnotations()和getAnnotations()的原因。

       d. @Documented

        表明在生成JavaDoc文档时,该注解也会出现在javaDoc文档中。

  • 相关阅读:
    [WEB]对于"Refused to execute script from 'http://xx.xx.xx/yy/zz.js' because its MIME type ('') is not executable, and strict MIME type checking is enabled."问题的解决办法
    Linux下为python3.6.5配置环境变量
    Yii2自带验证码实现
    php在Nginx环境下进行刷新缓存立即输出,实现常驻进程轮询。
    php文件锁解决少量并发问题
    过滤各种不合法标签数据
    wampserver下升级php7
    php异步请求(可以做伪线程)
    linux 定时执行shell
    记一次工单排查经历(修改显示时间)
  • 原文地址:https://www.cnblogs.com/lqtbk/p/10141455.html
Copyright © 2011-2022 走看看