Javadoc comments

 --Start with: /**

--End with: */

Special “tags” (@param; @result; etc;)

 

/**

*Sets the number of units earned (描述了這個方法的作用)

*@param units The number of units earned. (描述這個方法中的參數數, @param 後緊跟的units是參數名,這個參數units的意思就是,所得學分。)

*/

public void setUnits(double units){

unitsEarned = units

}

這不一定非常清晰,但只要你看過,便會記住和理解。但是計算機可以很好的理解,並創建很好的文獻資料。

URL: jtf.acm.org/javadoc/studentjtf javadoc的學生版,可以看到所有ACM庫的javadoc.當遇到問題時可以查閱。

所有的doc都是html的文檔。比如RandomGenerator的javadoc。這是一個機遇註釋和代碼自動生成的。

/**

*解釋了整個類的能力,比如,我們將要創建這個類,以追蹤這個學生。我在乎的是什麼呢?這是個很簡單的形式。我關心的是他的名字、ID以及他所得學分。這些是所有我們關心的內容。書中的例子還包括了其他內容。

*/

public class Student{

/**

*構造函數是什麼呢?我該如何創建學生呢?Stuent類並不是擴展而來的,所有的學生都只是對象而已,學生的構造函數設定了,(name,id),我們追蹤的是學生的信息,被存儲的實例變量。

*/

public Student(String name, int id){

studentName = name;

studentID = id;

}

/**

*Gets the name of this student.

*@return The name of the student.

*/

public String getName(){

return studentName;

}

/**

*Get the ID number of this student.

*@return The ID number of this student.

*/

public int getID(){

return studentID;

}

/**

*Sets the number of units earned.

*@param units The new number of units earned.

*/

public void setUnits(double units){

unitsEarned = units;

}

/**

*Gets the number of units earned

*@return The number of units the student has earned.

*/

public double getUnits(){

return unitsEarned;

}

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章