对于不更改实例状态的函数,该方法的javadoc注释通常与Java-API中@ return-tag的注释相同或非常相似.
boolean Collection.isEmpty()
现在我正在为许多简单的方法编写javadoc,比如getExpression(),我遇到同样的问题.我应该像在API中那样做还是把它留下来?
Ale*_*aev 23
从Oracle的建议如何为Javadoc工具编写Doc注释:
@return(参考页)
忽略@return表示返回void和构造函数的方法; 将其包含在所有其他方法中,即使其内容与方法描述完全不同.使用显式的@return标记可以让人们更容易快速找到返回值.尽可能为特殊情况提供返回值(例如指定提供越界参数时返回的值).
Sch*_*tod 22
如果你(像我一样)真的不喜欢违反DRY,那么这是javadoc ref中最重要的一行:
可以只有标签部分而没有主要描述的评论.
(@see http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javadoc.html#tagsection)
因此,编写javadoc的简单方法完全有效(并且正常工作),如:
/**
* @return the name of the object
*/
public String getName();
Run Code Online (Sandbox Code Playgroud)
所以你甚至可以这样写:
/**
* @return the n-th element of the object
*
* @param n index of element to get
*/
public String get( int n );
Run Code Online (Sandbox Code Playgroud)
这是(在稍微了解彼此之后)在源代码中更具可读性,并且作为违反DRY的更长形式更易于维护.
对于javadoc
16,您可以使用新的组合{@return ...}
标签来“避免在简单情况下重复返回信息”。
/**
* {@return the name of the object}
*/
public String getName();
Run Code Online (Sandbox Code Playgroud)
相当于(仍然支持)样式:
/**
* Returns the name of the object.
*
* @return the name of the object
*/
public String getName();
Run Code Online (Sandbox Code Playgroud)
在https://bugs.openjdk.java.net/browse/JDK-8075778 中查找更多详细信息
从 Java 16 开始,推荐的解决方案是使用标准 Doclet 新引入的内联标记:{@return description}
/**
* {@return the name} {@code null} if unknown.
*/
public String getName() {
...
}
Run Code Online (Sandbox Code Playgroud)
这将生成“退货说明”。摘要,后跟您在其后面编写的任何内容,并另外使用描述作为返回值的描述:
请注意,“Returns ...”句子已经以句点结尾;你不应该在后面添加一个明确的{@return }
。
归档时间: |
|
查看次数: |
36308 次 |
最近记录: |