zoukankan      html  css  js  c++  java
  • java自定义注解

    注解 可以用作来日志记录,给字段属性赋值,替代配置文件

    一、注解的基础

    1.注解的定义:Java文件叫做Annotation,用@interface表示。

    2.元注解:@interface上面按需要注解上一些东西,包括@Retention、@Target、@Document、@Inherited四种。

    3.注解的保留策略:

      @Retention(RetentionPolicy.SOURCE)   // 注解仅存在于源码中,在class字节码文件中不包含

      @Retention(RetentionPolicy.CLASS)     // 默认的保留策略,注解会在class字节码文件中存在,但运行时无法获得

      @Retention(RetentionPolicy.RUNTIME)  // 注解会在class字节码文件中存在,在运行时可以通过反射获取到

    4.注解的作用目标:

      @Target(ElementType.TYPE)                      // 接口、类、枚举、注解

      @Target(ElementType.FIELD)                     // 字段、枚举的常量

      @Target(ElementType.METHOD)                 // 方法

      @Target(ElementType.PARAMETER)            // 方法参数

      @Target(ElementType.CONSTRUCTOR)       // 构造函数

      @Target(ElementType.LOCAL_VARIABLE)   // 局部变量

      @Target(ElementType.ANNOTATION_TYPE) // 注解

      @Target(ElementType.PACKAGE)               // 包

    5.注解包含在javadoc中:

      @Documented

    6.注解可以被继承:

      @Inherited

    7.注解解析器:用来解析自定义注解。

  • 相关阅读:
    html5+css3中的background: -moz-linear-gradient 用法 (转载)
    CentOS 安装Apache服务
    Linux 笔记
    CURL 笔记
    Spring Application Context文件没有提示功能解决方法
    LeetCode 389. Find the Difference
    LeetCode 104. Maximum Depth of Binary Tree
    LeetCode 520. Detect Capital
    LeetCode 448. Find All Numbers Disappeared in an Array
    LeetCode 136. Single Number
  • 原文地址:https://www.cnblogs.com/qin-up/p/10106217.html
Copyright © 2011-2022 走看看