我是Java新手,我想问一个关于Javadoc评论的简单问题。可以说我有一个简单的方法:
public int getNumber()
Javadoc评论是 @return一个数字或 @return int一个数字?
答案 0 :(得分:1)
参考:
http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
编写javadocs的好技巧。
您无需在@return注释中指定“int”。因为这是方法签名的一部分,可以从那里推断出来。更准确的做法是描述你要返回的是什么类型的数字,即:解释这个数字是什么。
以下是您可以使用的示例:
/**
* 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;
}
}
答案 1 :(得分:0)
您不必具体说明方法的返回类型,因为它是方法签名的一部分。所以Javadoc评论只是 @return A Number 。但是,如果返回类型无效,则无需包含 @ return 注释。
如果您有兴趣了解更多内容,请参阅以下有关Javadoc评论的好文章:http://www.oracle.com/technetwork/articles/java/index-137868.html
编辑:刚刚意识到其他人之前发布了这个^链接,但它仍然是一个很好的来源:)