原文:
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.