如何为 getInstance 方法编写 Javadoc?
How to write Javadoc for a getInstance method?
假设我有这样的东西:
public class MyClass {
private static MyClass sInstance;
/**
*
* @return The {@link MyClass} application instance.
*/
public static MyClass getInstance() {
return sInstance;
}
}
IntelliJ 给我这个警告:
'@link' pointing to containing class is unnecessary
写这段Javadoc的proper/conventional方法是什么?
你会怎么写?
在JDK中,他们使用{@code}
。这不会生成可点击的 link,但您已经在查看无论如何都会被 link 编辑的页面。
例如(来自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}
*/
您只会收到警告,因为 link 不会去任何地方。只需将其更改为 {@code MyClass}
即可保留格式,但不包含 link.
以下是 JDK.
中的一些示例 getInstance()
方法
/**
* 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() {
/**
* 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() {
假设我有这样的东西:
public class MyClass {
private static MyClass sInstance;
/**
*
* @return The {@link MyClass} application instance.
*/
public static MyClass getInstance() {
return sInstance;
}
}
IntelliJ 给我这个警告:
'@link' pointing to containing class is unnecessary
写这段Javadoc的proper/conventional方法是什么?
你会怎么写?
在JDK中,他们使用{@code}
。这不会生成可点击的 link,但您已经在查看无论如何都会被 link 编辑的页面。
例如(来自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}
*/
您只会收到警告,因为 link 不会去任何地方。只需将其更改为 {@code MyClass}
即可保留格式,但不包含 link.
以下是 JDK.
中的一些示例getInstance()
方法
/**
* 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() {
/**
* 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() {