原文為:
Annotations――Java注解
你可能會遇到這類需求:通過與元數據(描寫其他數據的數據)關聯來注解你Java利用程序。1直以來,Java通過transient關鍵字提供了1種即時注解(ad hoc annotation)機制,這允許你標識1個成員變量在序列化進程中應當被疏忽。但是,直到java5才正式地引入了1種標準方式去注解程序。
Java5平臺提供了下面4種注解機制:
1. 聲明注解類型:@interface;
2. 元注解類型:可以辨認利用于注解類型的程序元素和注解的生命周期(注解類型的1個實例)等;
3.通過Java反射API的1種擴大方式來支持注解處理,你可以用來發現1個程序的運行時注解,并引入1個泛型Annotation處理工具(APT);
4. 標準的注解類型;
我將通過下面的實例解釋如何應用這些方式并闡明注解的難點。
Annotations
You’veprobably encountered the need to annotate elements of your Java applicationsbyassociating metadata (data that describes other data) with them.Java has always provided an ad hoc annotation mechanism via the transientreserved word, which lets you annotate fields that are to be excluded duringserialization. But it didn’t offer a standard way 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 to which an annotation type applies; to identify the lifetime of anannotation (an instance of an annotation type); and more.
3. Support for annotation processing via an extension to the Java ReflectionAPI, which you 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.
延續更新中。。。