@param究竟如何工作 - Java

use*_*462 24 java param

注释如何@param工作?

如果我有这样的事情:

/* 
*@param testNumber;
*/

int testNumber = 5;
if (testNumber < 6) {
   //Something
}
Run Code Online (Sandbox Code Playgroud)

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

谢谢.如果我错了,请告诉我.

rma*_*how 30

@paramjavadoc用于生成文档的特殊格式注释.它用于表示方法可以接收的参数(或参数)的描述.还有@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) {
Run Code Online (Sandbox Code Playgroud)


Kir*_*Koa 15

@param不会影响号码.这只是为了制作javadoc.

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

  • param 不影响方法。当您查看方法的详细信息时,它会向您显示您需要什么(按 后将鼠标悬停在方法上。)您甚至可以在 @param 之后添加更多内容,以提供有关参数的更多信息 (2认同)

use*_*660 6

@param不会影响testNumber。它是一个Javadoc注释-即用于生成文档。您可以在类、字段、方法、构造函数或接口之前添加Javadoc注释,例如@param, @return通常以“ @ ”开头,并且必须是该行的第一个内容。

使用的优点@param是: - 通过创建包含属性和一些自定义 Javadoc 标记的简单 Java 类,您允许这些类充当代码生成的简单元数据描述。

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

       if (testNumber < 6) {
          //Something
        }
     }
Run Code Online (Sandbox Code Playgroud)

每当在代码中重用 testNumberIsValid 方法时,IDE 都会向您显示该方法接受的参数以及该方法的返回类型。