Skip to content

java Annotations

cheyiliu edited this page Sep 26, 2014 · 6 revisions

Annotation 概念及作用

  • 概念
An annotation is a form of metadata, that can be added to Java source code. Classes, methods, variables,   
parameters and packages may be annotated. Annotations have no direct effect on the operation of the code they annotate.

能够添加到 Java 源代码的语法元数据。类、方法、变量、参数、包都可以被注解,可用来将信息元数据与程序元素进行关联。Annotation 中文常译为“注解”

  • 作用
  1. 标记,用于告诉编译器一些信息
  2. 编译时动态处理,如动态生成代码
  3. 运行时动态处理,如得到注解信息 这里的三个作用实际对应着后面自定义 Annotation 时说的 @Retention 三种值分别表示的 Annotation

Annotation 分类

  1. 标准 Annotation
  2. 元 Annotation
  3. 自定义 Annotation

Annotation 自定义

Annotation 解析

  • 运行时 Annotation 解析
  • 编译时 Annotation 解析
    TODO

ref

Clone this wiki locally