1. 程式人生 > >(44):為所有匯出的API元素編寫文件註釋

(44):為所有匯出的API元素編寫文件註釋

要想使一個API真正可用,就必須為其編寫文件。Java提供了Javadoc工具,使得為API編寫文件變得非常容易。Javadoc利用特殊格式的文件註釋,根據原始碼自動生成API文件。

示例:

/**
 * Returns the element at the specified position in this list.
 *
 * <p>This method is <i>not</i> guaranteed to run in constant
 * time. In some implementations it may run in time proportional
 * to the element position.
 *
 * @param index index of element to return; must be
 *        non-negative and less than the size of this list
 * @return the element at the specified position in this list
 * @throws IndexOutOfBoundsException if the index is out of range
 *         ({@code index < 0 || index >= this.size()})
 */
E get(int index);