简单的get方法javadoc
Simple get method javadoc
我是 Java 的新人,我想问一个关于 Javadoc 评论的简单问题。假设我有一个简单的方法:
public int getNumber()
Java文档注释将是 @return 一个数字 或 @return int 一个数字 ?
参考:
http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
关于编写 javadoc 的好技巧。
您无需在@return 注释中指定"int"。因为这是方法签名的一部分,可以从那里推断出来。更准确的做法是描述您正在 return 的数字类型,即:解释该数字是什么。
您可以使用以下示例:
/**
* 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) {
try {
return getImage(new URL(url, name));
} catch (MalformedURLException e) {
return null;
}
}
您不必特别说明方法的 return 类型,因为它是方法签名的一部分。所以 Javadoc 注释将只是 @return A Number。但是,如果 return 类型为空,则不需要包含 @ return 注释。
如果您有兴趣了解更多,这里有一篇关于 Javadoc 注释的好文章:http://www.oracle.com/technetwork/articles/java/index-137868.html
编辑:刚刚发现其他人发布了这个 ^ link 但它仍然是一个很好的来源:)
我是 Java 的新人,我想问一个关于 Javadoc 评论的简单问题。假设我有一个简单的方法:
public int getNumber()
Java文档注释将是 @return 一个数字 或 @return int 一个数字 ?
参考:
http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
关于编写 javadoc 的好技巧。
您无需在@return 注释中指定"int"。因为这是方法签名的一部分,可以从那里推断出来。更准确的做法是描述您正在 return 的数字类型,即:解释该数字是什么。
您可以使用以下示例:
/**
* 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) {
try {
return getImage(new URL(url, name));
} catch (MalformedURLException e) {
return null;
}
}
您不必特别说明方法的 return 类型,因为它是方法签名的一部分。所以 Javadoc 注释将只是 @return A Number。但是,如果 return 类型为空,则不需要包含 @ return 注释。
如果您有兴趣了解更多,这里有一篇关于 Javadoc 注释的好文章:http://www.oracle.com/technetwork/articles/java/index-137868.html
编辑:刚刚发现其他人发布了这个 ^ link 但它仍然是一个很好的来源:)