Javadoc 工具內建於 JDK bin/ 目錄。各版本對應:
每個文件註解的第一句需簡潔完整描述 API 項目,以「句點+空白」結束。若句中含縮寫 (如 e.g.),需轉義空白:e.g.\ 。
Overrides 或 Specified by。| 用途 | 標記 | 範例 |
|---|---|---|
| 關鍵字/名稱 | <code>...</code> | <code>String</code> |
| 行內連結 | {@link Class#member} | 節制使用 |
| 方法/建構子說明 | 省略括號 | getName 而非 getName() |
| 簡短敘述 | 可用片語 | 「Returns the name」優於「This method returns the name」 |
| 人稱 | 第三人稱 | 「Gets the name」非「Get the name」 |
| 動詞開頭 | 方法描述以動詞片語起頭 | 「Returns...」「Sets...」「Throws...」 |
| 類別/欄位描述 | 可省略主詞 | 「The name of the user」 |
| 指代當前實例 | 用 this 不用 the | 「Sets this object's name」 |
field 一詞易混淆(建議用 member variable)。@author (多位依貢獻時間排序)
@version
@param (依方法宣告順序,格式:@param 參數名 描述)
@return (非 void 必寫)
@exception / @throws (依例外類別字母序)
@see (依規定順序:#field, #Constructor, #method, Class, Class#member, package.Class...)
@since
@serial
@deprecated
@param 與 @return (非 void) 為必寫。
/**
* Returns the current user's display name.
* <p>
* If the user has not set a display name, the login name is returned.
*
* @return the display name, or login name if display name is not set
* @since 1.2
* @see #setDisplayName(String)
*/
public String getDisplayName() { ... }
遵循統一的 Javadoc 規範,能產出專業、一致、可維護的 API 文件,大幅降低團隊溝通成本與使用者學習曲線。