public static class Builder {
protected static final int DEFAULT_MAX_COUNT = 3;
/** count cannot be set to a value higher than this. By default, the value is {@value Builder#DEFAULT_MAX_COUNT}. */
protected int maxCount = DEFAULT_MAX_COUNT;
protected int count;
// ..some other code here
/**
* This should be greater than 0 and less than equal to {@link Builder#maxCount}. By default, {@value Builder#DEFAULT_MAX_COUNT}.
*
* @param count
* @throws IllegalArgumentException if count is less than 0 and greater than {@link Builder#maxCount}.
* @return Builder object
*/
public Builder setCount(int count) {
checkArgument(count > 0 && count < (maxCount + 1),
"count should be greater than 0 and less than " + (maxCount + 1));
this.count = count;
return this;
}
/** ... */
public Builder setMaxCount(int maxCount){
checkArgument(count > 0, "maxCount must be greater than 0");
this.maxCount = maxCount;
}
/** ... */
public int getMaxCount(int maxCount){
return this.maxCount;
}
}
maxCount
IMO,为in设置 setter 和 getter 是没有意义的,Builder
而应该是一个常量最大值(DEFAULT_MAX_COUNT
)。
javadoc 不能显示动态变量的值,因为文档不会随着程序的运行而改变。javadoc 只是文本,没有程序在运行,因此无法更新值。将其视为您的闹钟(程序)附带的手册(您的 javadoc)。手册可以告诉你各种有用的东西以及如何使用时钟,但它不能告诉你闹钟的设置是什么(因为它永远不会改变)。这些{@value ..}
东西就像时钟的序列号。'包装'时钟的人知道实际的序列号并将其写出来而不是 .
附言。完全希望这更符合您实际寻找的内容:
public static class Builder {
protected static final int MAX_MAX_COUNT = 3;
/** By default, the value is {@value Builder#MAX_MAX_COUNT}. */
protected int maxCount = MAX_MAX_COUNT;
// ..some other code here
/**
* This should be greater than 0 and less than equal to {@value Builder#MAX_MAX_COUNT}.
*
* @param maxCount
* @throws IllegalArgumentException if maxCount is less than 0 and greater than {@link Builder#MAX_MAX_COUNT}.
* @return Builder object
*/
public Builder setMaxCount(int maxCount) {
checkArgument(maxCount > 0 && maxCount < (MAX_MAX_COUNT + 1),
"count should be greater than 0 and less than " + (MAX_MAX_COUNT + 1));
this.maxCount = maxCount;
return this;
}
}