如何为getInstance方法编写Javadoc?

时间:2016-05-05 09:36:58

标签: java intellij-idea javadoc

说我有这样的事情:

public class MyClass {
    private static MyClass sInstance;

    /**
     *
     * @return The {@link MyClass} application instance.
     */
    public static MyClass getInstance() {
        return sInstance;
    }
}

IntelliJ给了我这个警告:

  

' @链路'指向包含类是不必要的

编写这段Javadoc的正确/传统方式是什么?

你会怎么写呢?

2 个答案:

答案 0 :(得分:5)

在JDK中,他们使用{@code}。这不会产生可点击的链接,但您已经在查看将要链接的页面。

例如(来自String.java):

  /**
  * Initializes a newly created {@code String} object so that it represents
  * the same sequence of characters as the argument; in other words, the
  * newly created string is a copy of the argument string. Unless an
  * explicit copy of {@code original} is needed, use of this constructor is
  * unnecessary since Strings are immutable.
  *
  * @param  original
  *         A {@code String}
  */

答案 1 :(得分:1)

您只会收到警告,因为该链接不会出现在任何地方。只需将其更改为{@code MyClass}即可保留格式,但不包含链接。

以下是JDK中的一些示例getInstance()方法。

java.text.Collator

/**
 * Gets the Collator for the current default locale.
 * The default locale is determined by java.util.Locale.getDefault.
 * @return the Collator for the default locale.(for example, en_US)
 * @see java.util.Locale#getDefault
 */
public static synchronized Collator getInstance() {

java.text.NumberFormat

/**
 * Returns a general-purpose number format for the current default
 * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
 * This is the same as calling
 * {@link #getNumberInstance() getNumberInstance()}.
 *
 * @return the {@code NumberFormat} instance for general-purpose number
 * formatting
 */
public final static NumberFormat getInstance() {