zoukankan      html  css  js  c++  java
  • java--annotation(注解)

    从下面的例子说起

    * @since 1.5
     * @jls 9.6.4.1 @Target
     * @jls 9.7.4 Where Annotations May Appear
     */
    @Documented
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.ANNOTATION_TYPE)
    public @interface Target {
        /**
         * Returns an array of the kinds of elements an annotation type
         * can be applied to.
         * @return an array of the kinds of elements an annotation type
         * can be applied to
         */
        ElementType[] value();
    }

    1.@Target(ElementType.FIELD)指定程序元注释所用的地方

    public enum ElementType {
        /** 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,
    
        /**
         * Use of a type
         *
         * @since 1.8
         */
        TYPE_USE
    }

    2.@Retention(RetentionPolicy.RUNTIME)

    public enum RetentionPolicy {
        /**
         * Annotations are to be discarded by the compiler.
         */
        SOURCE,
    
        /**
         * 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.
         */
        CLASS,
    
        /**
         * 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.
         *
         * @see java.lang.reflect.AnnotatedElement
         */
        RUNTIME
    }
  • 相关阅读:
    关于MySQL数据库优化的部分整理
    PHP跨域form提交
    px、dp和sp,这些单位有什么区别?
    301和302 Http状态有啥区别?
    PHP HTTP请求
    php的http_build_query使用
    nginx ssi 模块
    MongoDB学习笔记(一) MongoDB介绍及安装(摘)
    Django Admin 录入中文错误解决办法
    关于python字符串连接的操作
  • 原文地址:https://www.cnblogs.com/b-dong/p/6343054.html
Copyright © 2011-2022 走看看