2
我在可選參數的方法中使用varargs
。關於如何最好地記錄該方法的任何建議?適用於Javadoc的可變參數記錄
這裏是一個奇妙的人爲的例子:
/**
*
* @param consumption
* liters of liquid consumed after last pee
* @param options
* urgency
* how badly you have to pee on a scale of 1-3,
* 3 being the highest (default 1)
* bribe
* what's a toilet worth to you? (default 0)
* @return waitTime
* minutes until you'll be able to relieve yourself
*/
public integer whenCanIUseTheBathroom(int consumption, int... options){
// Segment handling options, defining defaults/fallbacks
int urgency = 1;
int bribe = 0;
if(options.length > 0) {
urgency = options[0];
}
if(options.length == 2) {
bribe = options[1];
}
// Segment determining one's fate
...
}
如果我明白你的javadoc試圖告訴我什麼,我可能會找到更清晰的方式來寫它...也許你應該給一個用法示例或定義什麼是「子參數」? – meriton
道歉,「subparam」是對'options'參數提供的選項的模糊/複雜的引用。我剛剛改進了示例代碼的清晰度。 – fny
你可能最好有明確的重載 - 可能重定向到接受所有選項的統一方法,默認或不是。 –