Javadoc注释规范
Javadoc雖然是Sun公司為Java文檔自動生成設計的,可以從程序源代碼中抽取類、方法、成員等注釋形成一個和源代碼配套的API幫助文檔。(Javadoc is a documentation generator from Sun Microsystems for generating API documentation in HTML format from Java source code. -- 維基百科)但是Javadoc的注釋也符合C的注釋格式,而且doxyen也支持該種風格的注釋,所以簡單學習一下。以下的內容來自官方文檔,維基百科和一些網上的文檔。
官方文檔:http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/javadoc.html
維基百科:http://en.wikipedia.org/wiki/Javadoc
Javadoc的注釋結構和C類似。都以/* 注釋 */這種結構。
?? ? Javadoc的內容很多,我只是先學習一下Overview注釋,類注釋和方法注釋,其他的以后再學。先貼出幾段Java的示例代碼。
Overview:
?
| /** ????* @author????? Firstname Lastname <address @ example.com> ????* @version???? 2010.0331???????????????????????????????? (E.g. ISO 8601 YYYY.MMDD) ????* @since?????? 1.6?????????????????????????????????????? (The Java version used) ????*/ ???public?class?Test { ?????// class body ???} |
Class:
?
?
| /** ?* A class representing a window on the screen. ?* For example: ?* <pre> ?*??? Window win = new Window(parent); ?*??? win.show(); ?* </pre> ?* ?* @author? Sami Shaio ?* @version %I%, %G% ?* @see???? java.awt.BaseWindow ?* @see???? java.awt.Button ?*/ class?Window extends?BaseWindow { ???... } |
Method:
?
?
| /** ?????* Returns the character at the specified index. An index ?????* ranges from <code>0</code> to <code>length() - 1</code>. ?????* ?????* @param???? index? the index of the desired character. ?????* @return??? the desired character. ?????* @exception StringIndexOutOfRangeException ?????*????????????? if the index is not in the range <code>0</code> ?????*????????????? to <code>length()-1</code>. ?????* @see?????? java.lang.Character#charValue() ?????*/ ????public?char?charAt(int?index) { ???????... ????} |
其實這些注釋形式都差不多,主要是tag不同下面介紹一下tag及含義。
|
|
|
| @author?name | Describes an author. 描述作者 | Class, Interface | ? |
| @version?version | Provides version entry. Max one per Class or Interface. 版本條目,每個類或接口最多有一個 | Class, Interface | ? |
| @since?since-text | Describes since when this functionality has existed. 描述這個功能塊從何時有的 | Class, Interface, Field, Method | ? |
| @see?reference | Provides a link to other element of documentation. 提供鏈接到其他文檔元素的鏈接 | Class, Interface, Field, Method | ? |
| @param?name description | Describes a method parameter. 描述一個參數 | Method | ? |
| @return?description | Describes the return value. 描述返回值 | Method | ? |
| @exception?classname description @throws?classname description | Describes an exception that may be thrown from this method. 描述該方法可能拋出的異常 | Method | ? |
| @deprecated?description | Describes an outdated method. 描述一個過期的方法 | Method | ? |
| {@inheritDoc} | Copies the description from the overridden method. 從復寫方法出拷貝來得描述 | Overriding Method | 1.4.0 |
| {@link?reference} | Link to other symbol. 連到其他的引用 | Class, Interface, Field, Method | ? |
| {@value} | Return the value of a static field. 返回一個靜態作用域的值 | Static Field | 1.4.0 |
from:?http://www.cnblogs.com/allen8807/archive/2010/11/10/1873703.html
總結
以上是生活随笔為你收集整理的Javadoc注释规范的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java线程池框架核心代码分析
- 下一篇: 如何写Java文档注释(Java Doc