javadoc 的默认值

Default value for javadoc

我有一个图书馆 AppConfig class。

告知其他使用此库的开发人员 AppConfig 中的默认值是什么的最佳方式是什么?

我的一个想法是在 javadoc 中提到它,像这样:

public class AppConfig {
   private int someSetting = 50;

   /**
    * This setting does something.
    *
    * @default 50
    */
   public int setSomeSetting(int someSetting){
      this.someSetting = someSetting;
   }
}

但是这个场景的实际最佳实践是什么?

(我相信 @default 不是真正受支持的标签)

正确;没有这样的注释。

从那里开始:这只是 "pure style";意思是:javadoc 很好——你可以做任何对你有用的事情;分别是您周围将使用此 class.

的团队

但真正棘手的问题是:将那条信息放在哪里?!您会看到:当 class setSomeSetting() 的用户...您 已经 应用了该默认值。

换句话说:您可能在构造函数中使用了这些默认值。因此,您应该直接在 "class javadoc" 中告诉用户这些默认值;可能还有他们的价值观。

喜欢:

/**
 * ... Provides properties x, y,z; with defaults 50, 100, 150
 */
public class Foo {
  public final int BAR_DEFAULT = 50; 
  private int bar = BAR_DEFAULT;

  public void setBar(int newBar) { bar = newBar; }