注釋
文件頭注釋
文件頭注釋以 /*開始,以*/結束,需要注明該文件創建時間,文件名,命名空間信息。
例如:
/*
* @(#)Boolean.java 1.51 04/05/11
*
* Copyright 2004 Sun Microsystems, Inc. All
rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject
to license terms.
*/
類、接口注釋
類、接口的注釋采用 /** … */,描述部分用來書寫該類的作用或者相關信息,塊標記部分必須注明作者和版本。Import語句之后,類定義之前。
例如:
/**
* The Boolean class wraps a value of the
primitive type
* <code>boolean</code> in an object. An object of type
* <code>Boolean</code> contains a single field whose type is
* <code>boolean</code>.
* <p>
* In addition, this class provides many
methods for
* converting a <code>boolean</code> to a <code>String</code> and a
* <code>String</code> to a <code>boolean</code>, as well as other
* constants and methods useful when dealing
with a
* <code>boolean</code>.
*
* @author Arthur van Hoff
* @version 1.51, 05/11/04
* @since JDK1.0
*/
方法注釋采用/** … */,描述部分注明方法的功能,塊標記部分注明方法的參數,返回值,異常等信息。
/**
* Compares this <tt>Boolean</tt> instance with
another.
*
* @param b the <tt>Boolean</tt> instance to be
compared
* @return zero if this object represents the same
boolean value as the
* argument; a positive value if this
object represents true
* and the argument represents false;
and a negative value if
* this object represents false and the
argument represents true
* @throws NullPointerException if the argument is <tt>null</tt>
* @see
Comparable
* @since 1.5
*/
@param后面空格后跟著參數的變量名字(不是類型),空格后跟著對該參數的描述。
@return標記返回為空(void)的構造函數或者函數,@return可以省略。
如果返回值就是輸入參數,必須用與輸入參數的@param相同的描述信息。
必要的時候注明特殊條件寫的返回值。
@deprecated由于某種原因而被宣布將要被廢棄的方法。
@see:引用其它類的文檔,相當于超鏈接,Javadoc會在其生成的HTML文件中,將@see標簽鏈到其他的文檔
@see package.classname#feature label
@see <a href=”…”>label</a>
@see “text”
@link標記
語法:{@link package.class#member label}
Label為鏈接文字。
package.class#member將被自動轉換成指向package.class的member文件的URL。
@since
類注釋標記。
標明該類可以運行的JDK版本