元注解

作者: qpan | 来源:发表于2018-04-27 15:32 被阅读4次
  • 包括
    Target
    Retention
    Documented 为像Javadoc这样的归档工具提供了一些提示
    Inherited 只能应用于对类的注解。指明当这个注解应用于一个类的时候,能够自动被它的子类继承

  • 介绍
    @Retention 用于声明该注解生效的生命周期,有三个枚举值可以选择

  1. RetentionPolicy.SOURCE 注释只保留在源码上面,编译成 class 的时候自动被编译器抹除
    Annotations are to be discarded by the compiler.

  2. RetentionPolicy.CLASS 注释只保留到字节码上面,VM 加载字节码时自动抹除
    Annotations are to be recorded in the class file by the compiler
    but need not be retained by the VM at run time. This is the default
    behavior.

  3. RetentionPolicy.RUNTIME 注释永久保留,可以被 VM 加载时加载到内存中
    Annotations are to be recorded in the class file by the compiler and
    retained by the VM at run time, so they may be read reflectively.

@Target 用于指定该注解可以声明在哪些成员上面
常见的值有

    /**Class, interface (including annotation type), or enum declaration */
    TYPE,

    /** Field declaration (includes enum constants) */
    FIELD,

    /** Method declaration */
    METHOD,

    /** Formal parameter declaration */
    PARAMETER,

    /** Constructor declaration */
    CONSTRUCTOR,

    /** Local variable declaration */
    LOCAL_VARIABLE,

    /** Annotation type declaration */
    ANNOTATION_TYPE,

    /** Package declaration */
    PACKAGE,

    /**
     * Type parameter declaration
     *
     * @since 1.8
     */
    TYPE_PARAMETER

相关文章

  • 1.8 Java 注解annotation

    1.1 注解声明 Java注解Annotation,有声明注解和元注解 元注解:Java提供的元注解,所谓元注解就...

  • JavaSE进阶-注解:JavaSE元注解和JavaEE原生注解

    JavaSE元注解 在注解定义时,用在注解头部的注解,称为元注解,目前元注解在java.lang.annotati...

  • Java注解

    Java注解 1.注解的语法 2.元注解 2.1 元注解列表 元注解含义选项@Retention标识注解的存活阶段...

  • java - 注解

    1. 元注解 元注解:用在注解上的注解,java1.5后添加的4个元注解: @Target @Retention ...

  • java.lang.Annotation源码学习

    元注解 元注解就是标记其他注解的注解,包括:@Documented,@Inherited,@Repeatable,...

  • JAVA之元注解

    元注解:负责对其他注解进行说明的注解,自定义注解时可以使用元注解。元注解主要包含@Document、@Target...

  • 自定义@Service、@Autowired、@Transact

    1. 自定义注解首先要了解一些JDK提供的元注解 元注解 元注解是可以注解到注解上的注解,或者说元注解就是一种基本...

  • Java annotation

    元注解 元注解是指注解的注解。包括 @Retention @Target @Document @Inherited...

  • 注解的使用

    元注解 注解 注解本质就是接口: 元注解:修饰注解的注解 自定义注解 Text.java FruitName.ja...

  • 分享:自定义JAVA注解

    元注解 元注解指用来定义注解的注解,例如:@Retention @Target Inherited @Docume...

网友评论

      本文标题:元注解

      本文链接:https://www.haomeiwen.com/subject/tvrplftx.html