@Claudiu
When I write code that others will use – Yes. Every method that somebody else can use (any public method) should have a javadoc at least stating its obvious purpose.
@丹尼尔Spiewak
I thoroughly document every public method in every API class. Classes which have public members but which are not intended for external consumption are prominently marked in the class javadoc. I also document every protected method in every API class, though to a lesser extent. This goes on the idea that any developer who is extending an API class will already have a fair concept of what’s going on.
Finally, I will occasionally document private and package private methods for my own benefit. Any method or field that I think needs some explanation in its usage will receive documentation, regardless of its visibility.
@保罗德Vrieze
For things, like trivial getters and setters, share the comment between then and describe the purpose of the property, not of the getter/setter
/**
* Get the current value of the foo property.
* The foo property controls the initial guess used by the bla algorithm in
* {@link #bla}
* @return The initial guess used by {@link #bla}
*/
int getFoo() {
return foo;
}
是的,这是更多的工作。
@VonC
>一个公共方法调用
>几种私有方法,代表公共内部步骤
,它对javadoc的私有方法也非常有用,即使该文档在javadoc API文件中不可见。
仍然,它允许您更容易记住您的复杂算法的不同步骤的精确性质。
另外,javadoc比简单的“// comment”更好:
>它由IDE识别,用于在将您的光标移动到其中一个 – javadoc-ed – 函数之上时显示一个弹出窗口。例如,一个常量 – 即私有静态最终变量 – ,应该有一个javadoc,尤其是当它的值不是微不足道。例子:regexp(它的javadoc应该包括其非转义形式的regexp,什么是目的是和regexp匹配的文字示例)
>它可以通过外部工具(如xdoclet)解析,
@Domci
For me, if somebody will see it or not doesn’t matter – it’s not likely I’ll know what some obscure piece of code I wrote does after a couple of months. […]
In short, comment logic, not syntax, and do it only once, on a proper place.
@Miguel Ping
In order to comment something, you have to understand it first. When you trying to comment a function, you are actually thinking of what the method/function/class does, and this makes you be more specific and clear in your javadoc, which in turn makes you write more clear and concise code, which is good.