Java如何寫注釋__Java

來源:互聯網
上載者:User
整個類檔案注釋

樣本如下 :

/*

  * @(#)Object.java     1.61 03/01/23

  *

  * Copyright 2003 Sun Microsystems, Inc. All rights reserved.

  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.

  */

 

package java.lang;

 

注釋結構 :

/*

  * @(#){ 類名稱 }.java       { 建立時間 }

  *

  * { 某人或某公司具有完全的著作權 }

  * { 使用者必須經過許可 }

  */

 

package java.lang;

 

 

2.     具體類功能注釋

樣本如下 :

/**

  * Class <code>Object</code> is the root of the class hierarchy.

  * Every class has <code>Object</code> as a superclass. All objects,

  * including arrays, implement the methods of this class.

  *

  * @author  unascribed

  * @version 1.61, 01/23/03

  * @see     java.lang.Class

  * @since   JDK1.0

  */

public class Object {}

 

注釋結構 :

/**

  * 類 <code>{ 類名稱 }</code>{ 此類功能描述 }

  *

  * @author  { 作者 }

  * @version { 版本 , 常用時間代替 }

  * @see     java.lang.Class

  * @since   JDK{jdk 版本 }

  */

public class Object {}

 

3.     類變數注釋

樣本如下 :

/** The value is used for character storage. */

  private char value[];

 

注釋結構 :

  /** { 此值是用來儲存 / 記錄什麼的 }*/

  private String str ;

 

4.     類方法注釋

樣本如下 :

     /**

     * Returns a new string that is a substring of this string. The

     * substring begins with the character at the specified index and

     * extends to the end of this string. <p>

     * Examples:

     * <blockquote><pre>

     * "unhappy".substring(2) returns "happy"

     * "Harbison".substring(3) returns "bison"

     * "emptiness".substring(9) returns "" (an empty string)

     * </pre></blockquote>

     *

     * @param      beginIndex   the beginning index, inclusive.

     * @return     the specified substring.

     * @exception  IndexOutOfBoundsException  if

     *             <code>beginIndex</code> is negative or larger than the

     *             length of this <code>String</code> object.

     */

public String substring(int beginIndex) {

return substring(beginIndex, count);

}

 

注釋結構 :

     /**

      * { 方法的功能 / 動作描述 }

     *

     * @param      { 引入參數名 }   { 引入參數說明 }

     * @return       { 返回參數名 }   { 返回參數說明 }

     * @exception    { 說明在某情況下 , 將發生什麼異常 }

     */

public String substring(int beginIndex) {

return substring(beginIndex, count);

}

 

 

5.     類方法中代碼塊注釋

樣本如下 :

/*

* 調用持久化類,將資料儲存到庫

*

* 判斷是添加,還是修改

*/

boolean ifSucc = false;

if(request.getParameter("YINGLI_ID")==null){

       String GUID = new RandomGUID().toString();

       stressTestDataBean.setUSER_ID(Integer.toString(userId));

       stressTestDataBean.setSIGN_ISBN((String)vSectNum.get(0));

       stressTestDataBean.setSHENHE_JIEGUO("0");

       stressTestDataBean.setGUID(GUID);

       stressTestDataBean.setCREATE_DATE("getdate()");

       stressTestDataBean.setSTATE("A");

                                         

       ifSucc = StressTestDataDao.addStressTestData(db,stressTestDataBean);

}else{

       ifSucc = StressTestDataDao.mendStressTestData(db,stressTestDataBean);

}

 

 

注釋結構 :

/*

* { 功能描述 }

*

* { 具體實現動作 }

*/

boolean ifSucc = false;

if(request.getParameter("YINGLI_ID")==null){

       String GUID = new RandomGUID().toString();

       stressTestDataBean.setUSER_ID(Integer.toString(userId));

       stressTestDataBean.setSIGN_ISBN((String)vSectNum.get(0));

       stressTestDataBean.setSHENHE_JIEGUO("0");

       stressTestDataBean.setGUID(GUID);

       stressTestDataBean.setCREATE_DATE("getdate()");

       stressTestDataBean.setSTATE("A");

                                         

       ifSucc = StressTestDataDao.addStressTestData(db,stressTestDataBean);

}else{

       ifSucc = StressTestDataDao.mendStressTestData(db,stressTestDataBean);

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.