在其风格指南<code>中,Oracle 建议在以下情况下使用Javadoc 中的标签:
我个人认为“类名”、“字段名”和“Java 关键字”的情况特别麻烦,因为我发现这些描述的可读性较差。例如:
/**
* Returns <code>true</code> if <code>x</code> is greater than
* <code>y</code> otherwise returns <code>y</code>.
*/
public Boolean greaterThan(int x, int y) { return (x > y); }
Run Code Online (Sandbox Code Playgroud)
我意识到上面的例子本身是任意的,但是对更复杂的函数的更长的描述最终也会变得同样难看。我知道目标是在 IDE 中使描述更漂亮,但是查看类的 java 文件本身很痛苦。
我正在考虑上述<code>标签,除非文档包含完整的代码示例。我是否有理由不这样做?
例子:
/**
* This method returns <code>true</code> when the sun is shining.
*
* @param weather - A <code>package.name.Weather</code> implementation
* representing the weather to be analyzed.
* return <code>true</code> if the sun is shining, else <code>false</code>.
*/
public boolean isSunShining(Weather weather) {
boolean result = false; // boolean variable for the result. Default is false.
// some more code
/*
* Multiline comment w/o markup
*/
return result;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3287 次 |
| 最近记录: |