简单的Getter / Setter注释 [英] Simple Getter/Setter comments
问题描述
您使用什么约定来评论getter和setter?这是我想知道的一段时间,例如:
What convention do you use to comment getters and setters? This is something I've wondered for quite some time, for instance:
/**
* (1a) what do you put here?
* @param salary (1b) what do you put here?
*/
public void setSalary(float salary);
/*
* (2a) what do you put here?
* @return (2b)
*/
public float getSalary();
我总是发现我几乎写的是1a / b和2a / b ,类似1a)设置雇员的工资,1b)雇员的工资。它只是似乎如此多余。现在我可以看到更复杂的东西,你可能在(a)部分写更多,给予上下文,但对于大多数getters / setters在那里的措辞几乎完全一样。
I always find I'm pretty much writing the exact same thing for 1a/b and 2a/b, something like 1a) Sets the salary of the employee, 1b) the salary of the employee. It just seems so redundant. Now I could see for something more complex you might write more in the (a) parts, to give context, but for a majority of the getters/setters out there the wording is almost exactly the same.
我只是好奇,如果,对于简单的getters / setters它的确定只填充(a)部分或(b)部分。
I'm just curious if, for the simple getters/setters its ok to only fill in either the (a) part OR the (b) part.
你觉得怎么样?
推荐答案
我通常只是填写param部分的setters,@return部分getters:
I usually just fill the param part for setters, and the @return part for getters:
/**
*
* @param salary salary to set (in cents)
*/
public void setSalary(float salary);
/**
* @return current salary (in cents, may be imaginary for weird employees)
*/
public float getSalary();
这样javadoc检查工具(例如Eclipse的警告)会出来干净,没有重复。
That way javadoc checking tools (such as Eclipse's warnings) will come out clean, and there's no duplication.
这篇关于简单的Getter / Setter注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!