Annotations
2015-06-05 17:53
495 查看
原文:
You\'ve probably encountered the need to annotate elements of your Java applications by associating metadata (data that describes other data) with them. Java has always provided an ad hoc annotation mechanism via the transient reserved word, which lets you
annotate fields that are to be excluded during serialization. But it didn\'t offer a standard way to annotate program elements until Java 5.
Java 5\'s general annotation mechanism consists of four components:
1.An @interface mechanism for declaring annotation types.
2.Meta-annotation types, which you can use to identify the application elements to which an annotation type applies; to identify the lifetime of an annotation (an instance of an annotation type); and more.
3.Support for annotation processing via an extension to the Java Reflection API, which you can use to discover a program\'s runtime annotations, and the introduction of a generalized tool for processing annotations.
4.Standard annotation types.
I\'ll explain how to use these components and point out some of the challenges of annotations in the examples that follow.
译文:
你可能曾遇到过这种需求:通过关联元数据(描述其他数据的数据)来注解你的java应用程序元素。一直以来,java通过transient关键字来提供一种即时注解机制,它可以让你标注一个成员变量在序列化过程中被排除。但是,直到java 5.0版本才提供一种标准的方式来注解程序。
Java 5.0常规注解机制包括四部分:
1. 声明注解类型@interface机制
2. 元注解类型,你可以用来识别注解类型的程序元素应用以及注解的声明周期(注解类型的一个实例)等;
3. 通过java反射API的扩展来支持注解处理,你可以用来发现程序运行时的注解,并引入一个泛型注解处理工具。
4. 标准的注解类型。
接下来,我将通过下面的例子解释如何运用这些机制,并对一些比较有挑战性的注解部分进行标明。
You\'ve probably encountered the need to annotate elements of your Java applications by associating metadata (data that describes other data) with them. Java has always provided an ad hoc annotation mechanism via the transient reserved word, which lets you
annotate fields that are to be excluded during serialization. But it didn\'t offer a standard way to annotate program elements until Java 5.
Java 5\'s general annotation mechanism consists of four components:
1.An @interface mechanism for declaring annotation types.
2.Meta-annotation types, which you can use to identify the application elements to which an annotation type applies; to identify the lifetime of an annotation (an instance of an annotation type); and more.
3.Support for annotation processing via an extension to the Java Reflection API, which you can use to discover a program\'s runtime annotations, and the introduction of a generalized tool for processing annotations.
4.Standard annotation types.
I\'ll explain how to use these components and point out some of the challenges of annotations in the examples that follow.
译文:
你可能曾遇到过这种需求:通过关联元数据(描述其他数据的数据)来注解你的java应用程序元素。一直以来,java通过transient关键字来提供一种即时注解机制,它可以让你标注一个成员变量在序列化过程中被排除。但是,直到java 5.0版本才提供一种标准的方式来注解程序。
Java 5.0常规注解机制包括四部分:
1. 声明注解类型@interface机制
2. 元注解类型,你可以用来识别注解类型的程序元素应用以及注解的声明周期(注解类型的一个实例)等;
3. 通过java反射API的扩展来支持注解处理,你可以用来发现程序运行时的注解,并引入一个泛型注解处理工具。
4. 标准的注解类型。
接下来,我将通过下面的例子解释如何运用这些机制,并对一些比较有挑战性的注解部分进行标明。
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树
- [原创]java局域网聊天系统