1、什麼是annotationjava
java.lang.annotation,接口 Annotation。對於Annotation,是Java5的新特性,JDK5引入了Metadata(元數據)很容易的就可以調用Annotations。Annotations提供一些原本不屬於程序的數據,好比:一段代碼的做者或者告訴禁止一編譯器些特殊的錯誤。An annotation 對代碼的執行沒有什麼影響。Annotations使用@annotation的形式應用於代碼:類(class),屬性(attribute),方法(method)等等。一個Annotation出如今上面提到的開始位置,並且通常只有一行,也能夠包含有任意的參數app
2、已實現類ide
public interface Annotation全部 annotation 類型都要擴展的公共接口。注意,手動擴展該公共接口的接口不定義 annotation 類型。還要注意此接口自己不定義 annotation 類型。
對於Annotation,是Java5的新特性,下面是Sun的Tutorial的描述,由於是英文,這裏我翻譯下,但願可以比較清晰的描述一下Annotation的語法以及思想。Annotation:Release 5.0 of the JDK introduced a metadata facility called annotations. Annotations provide data about a program that is not part of the program,such as naming the author of a piece of code or instructing the compiler to suppress specific errors. An annotation has no effect on how the code performs. Annotations use the form @annotation and may be applied to a program's declarations: its classes,fields,methods,and so on. The annotation appears first and often (by convention) on its own line,and may include optional arguments: JDK5引入了Metadata(元數據)很容易的就可以調用Annotations.Annotations提供一些原本不屬於程序的數據,好比:一段代碼的做者或者告訴
編譯器禁止一些特殊的錯誤。An annotation 對代碼的執行沒有什麼影響。Annotations使用@annotation的形式應用於代碼:類(class),屬性(field),方法(method)等等。一個Annotation出如今上面提到的開始位置,並且通常只有一行,也能夠包含有任意的參數。