Original: Programming with Typesafe enums and annotations in Java 5
Annotations--java annotations
You may encounter this requirement: Annotate your Java application by associating it with metadata that describes the data of other data. Java has been providing an instant annotation (ad hoc annotation) mechanism through the transient keyword, which allows you to identify a member variable that should be ignored during serialization. However, until JAVA5 formally introduced a standard way to annotate a program.
The JAVA5 platform provides the following four types of annotation mechanisms:
1. Statement of annotation type: @interface;
2. Meta-annotation types: You can identify the life cycle of program elements and annotations that apply to annotation types (one instance of the annotation type), and so on;
3. An extension of the Java Reflection API to support annotation processing allows you to discover the runtime annotations of a program and introduce a generic annotation processing tool (APT);
4. The standard annotation type;
I will explain how to use these methods and clarify the difficulty of annotations through the following examples.
Annotations
You ' veprobably encountered the need to annotate elements of your JaVA applications byassociating Metadata (data, describes other data) with them. Java have always provided a ad hoc annotation mechanism via the transientreserved Word, which lets you Annota Te fields, is to be excluded duringserialization. But it didn's offer a standard-to-annotate program Elementsuntil Java 5.
Java5 ' 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 applicationelements-which an annotation type applies; To identify the lifetime of anannotation (a instance of an annotation type); and more.
3. Support for annotation processing via an extension to the Java Reflectionapi, which-can use-to-Discover a program ' s runtime annotations, and theintroduction of a generalized tool for processing annotations.
4. Standard annotation types.
I ' ll explain how to use these Componentsand point out some of the challenges of annotations in the examples Thatfollow.
Continuous update ...
Translated programming with Typesafe enums and annotations in Java 5