註釋@param
的工作原理是什麼?@param的工作原理 - Java
如果我有這樣的事情:
/*
*@param testNumber;
*/
int testNumber = 5;
if (testNumber < 6) {
//Something
}
將如何@param
影響testNumber?它甚至會影響testNumber嗎?
謝謝。讓我知道如果我用錯了。
註釋@param
的工作原理是什麼?@param的工作原理 - Java
如果我有這樣的事情:
/*
*@param testNumber;
*/
int testNumber = 5;
if (testNumber < 6) {
//Something
}
將如何@param
影響testNumber?它甚至會影響testNumber嗎?
謝謝。讓我知道如果我用錯了。
@param
不會影響數量。我相信這只是爲了製作javadoc。
更多的javadoc: http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
就我所知,這是正確的。你可以把'@param blahblah'放到參數'blahblah'上。參數 – 2013-04-22 01:46:25
不影響該方法。在查看方法的詳細信息時,它會顯示您需要的內容(在按下後將鼠標懸停在方法上)。您甚至可以在@param之後添加更多以提供有關參數的更多信息 – 2013-04-22 02:06:26
@param
是使用的javadoc生成文檔的特殊格式註釋。它用於表示方法可以接收的參數(或參數)的描述。這裏還有@return
和@see
用來描述返回值和相關的信息,分別爲:
http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#format
有,除其他事項外,本:
/**
* Returns an Image object that can then be painted on the screen.
* The url argument must specify an absolute {@link URL}. The name
* argument is a specifier that is relative to the url argument.
* <p>
* This method always returns immediately, whether or not the
* image exists. When this applet attempts to draw the image on
* the screen, the data will be loaded. The graphics primitives
* that draw the image will incrementally paint on the screen.
*
* @param url an absolute URL giving the base location of the image
* @param name the location of the image, relative to the url argument
* @return the image at the specified URL
* @see Image
*/
public Image getImage(URL url, String name) {
@param
不會影響testNumber.It是Javadoc
評論 - 即用於生成文檔。 您可以在類,字段,方法,構造函數或接口(如@param
,@return
)之前立即添加Javadoc
註釋。 通常以'@'開頭,並且必須是第一件事。
使用@param
的好處是: - 通過創建包含屬性和一些自定義Javadoc標籤的簡單Java類,您可以將這些類用作代碼生成的簡單元數據描述。
/*
*@param testNumber
*@return integer
*/
public int main testNumberIsValid(int testNumber){
if (testNumber < 6) {
//Something
}
}
只要在你的代碼,如果你重用testNumberIsValid方法,IDE會告訴你的方法接受的參數和返回的方法的類型。
它基本上是一個評論。正如我們所知道的,許多在同一個項目上工作的人員必須具有關於代碼更改的知識。我們在程序中對參數做了一些說明。
以'/ **'開始並以'* /'結尾的塊僅由'javadoc'處理。它們被Java編譯器視爲'comments'。 – 2013-04-22 01:46:19