我注意到,Eclipse的打印diferent格式註釋:是什麼/ * ... * /之間的差異/ ** ... */
/* Eclipse prints it in green
*/
,或者如果你寫:
/** Eclipse prints it in blue
*/
這兩種評論有什麼區別?
我注意到,Eclipse的打印diferent格式註釋:是什麼/ * ... * /之間的差異/ ** ... */
/* Eclipse prints it in green
*/
,或者如果你寫:
/** Eclipse prints it in blue
*/
這兩種評論有什麼區別?
/*
* It is multi-line comment in Java
*
*/
/**
* It is a Javadoc. Can be found above methods and Class definitions.
*
*
*/
下面是Wikipedia有關的Javadoc一個摘錄:
Javadoc註釋從代碼通過標準多行註釋掀起 標籤/ *和* /。開始標記(稱爲開始註釋分隔符),具有 額外的星號,如在/ **中。
The first paragraph is a description of the method documented. Following the description are a varying number of descriptive tags, signifying: The parameters of the method (@param) What the method returns (@return) Any exceptions the method may throw (@throws) Other less-common tags such as @see (a "see also" tag)
類級別的Javadoc示例:
/**
* @author Firstname Lastname <address @ example.com>
* @version 1.6 (current version number of program)
* @since 2010-03-31 (the version of the package this class was first added to)
*/
public class Test {
// class body
}
方法級別的Javadoc示例:
/**
* Short one line description.
* <p>
* Longer description. If there were any, it would be
* here.
* <p>
* And even more explanations to follow in consecutive
* paragraphs separated by HTML paragraph breaks.
*
* @param variable Description text text text.
* @return Description text text text.
*/
public int methodName (...) {
// method body with a return statement
}
/* ... */
是一個簡單的評論。
/** ... */
是一個javadoc,然後可以通過被稱爲,奇怪的是,javadoc
工具被轉換成一個很好的HTML文檔。這個工具考慮了javadoc註釋本身,類/接口/方法的聲明,以及其他任何超級/子類實現/合約(例如,在創建方法的「由...指定」和「覆蓋」信息時)。最值得注意的例子是Java SE API doc itself。
此文檔評論包含自己的標記,例如@see Bar
。它可以指定編程方面的考慮因素,例如方法參數及其描述,方法的返回類型,聲明要拋出的方法的異常以及它們將被拋出的環境以及其他信息。
例如,ArrayList#toArray()
記錄爲
public <T> T[] toArray(T[] a)
返回包含所有在此列表中的元素上以正確 序列的陣列(從第一個到最後一個元素); 返回的數組的運行時類型是指定數組的類型。如果列表適合 指定的數組,則返回其中。否則,將使用指定數組的運行時類型和此列表的大小 分配一個新陣列 。
如果列表以房間指定的數組以備用(即, 陣列具有比所述列表多個元素)的配合,立即收集的末尾的數組 在元件被設置爲空。(這 在確定只有當呼叫者 知道列表不包含任何空元素的列表的長度是有用的。)
指定者:接口Collection
指定者指定者:
指定者:接口List
覆蓋:
指定者類AbstractCollection
個類型參數:
T
- 運行時類型的數組以包含收集
參數:
a
- 入列表的元素被存儲,如果它是足夠大的陣列;否則,將爲此分配一個相同運行時類型的新數組。
返回:
包含列表
拋出的元素的數組:
ArrayStoreException
- 如果指定的數組的運行時類型不是運行時類型每個元素的此列表中的超類型
NullPointerException
- 如果指定的數組爲null
從
/**
* Returns an array containing all of the elements in this list in proper
* sequence (from first to last element); the runtime type of the returned
* array is that of the specified array. If the list fits in the
* specified array, it is returned therein. Otherwise, a new array is
* allocated with the runtime type of the specified array and the size of
* this list.
*
* <p>If the list fits in the specified array with room to spare
* (i.e., the array has more elements than the list), the element in
* the array immediately following the end of the collection is set to
* <tt>null</tt>. (This is useful in determining the length of the
* list <i>only</i> if the caller knows that the list does not contain
* any null elements.)
*
* @param a the array into which the elements of the list are to
* be stored, if it is big enough; otherwise, a new array of the
* same runtime type is allocated for this purpose.
* @return an array containing the elements of the list
* @throws ArrayStoreException if the runtime type of the specified array
* is not a supertype of the runtime type of every element in
* this list
* @throws NullPointerException if the specified array is null
*/
如果只有人知道[JavaDoc的威力](https://www.youtube.com/watch?v=DGa6MAibjzA) – 2014-11-23 16:58:00
他們3種意見在Java中:
單LIGNE評論
// This is a single line comment
多行註釋
/* This is a
multi-line comment */
文檔註釋
/**
* This is a <b>documentation comment</b>
*/
編譯器將忽略所有這些,但javadoc工具將使用doc註釋生成javadoc,您可以在那裏使用HTML
格式。您也可以使用標籤,如@see
或@author
不僅僅是HTML - 還有一組javadoc專用標籤。 – hexafraction 2014-11-23 17:00:03
是的,我編輯了我的答案 – ToYonos 2014-11-23 17:01:03
後者是Javadoc。 – 2014-11-23 16:47:05