@param究竟如何工作 - Java

时间:2013-04-22 01:42:20

标签: java param

注释@param如何工作?

如果我有这样的事情:

/* 
*@param testNumber;
*/

int testNumber = 5;
if (testNumber < 6) {
   //Something
}

@param如何影响testNumber?它甚至会影响testNumber吗?

感谢。如果我错了,请告诉我。

5 个答案:

答案 0 :(得分:27)

@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) {

答案 1 :(得分:14)

@param不会影响这个数字。它只是为了制作javadoc。

有关javadoc的更多信息: http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html

答案 2 :(得分:3)

@param不会影响testNumber。它是Javadoc注释 - 即用于生成文档。 您可以在类,字段,方法,构造函数或界面(例如Javadoc@param)之前立即添加@return条评论。 通常以“ @ ”开头,并且必须是第一件事。

使用@param的好处是: - 通过创建包含属性和一些自定义Javadoc标记的简单Java类,您可以将这些类用作代码生成的简单元数据描述。

    /* 
       *@param testNumber
       *@return integer
    */
    public int main testNumberIsValid(int testNumber){

       if (testNumber < 6) {
          //Something
        }
     }

如果您在代码中重用testNumberIsValid方法,IDE将显示方法接受的参数并返回方法的类型。

答案 3 :(得分:0)

基本上是评论。众所周知,在同一项目中工作的许多人必须了解代码更改。我们在程序中做了一些关于参数的注释。

答案 4 :(得分:0)

您可能会错过@author,并且在@param内需要解释该参数的含义,使用方法等。

相关问题