如何在javadoc中添加对方法参数的引用?


313

有没有一种方法可以从方法文档主体中添加对一个或多个方法参数的引用?就像是:

/**
 * When {@paramref a} is null, we rely on b for the discombobulation.
 *
 * @param a this is one of the parameters
 * @param b another param
 */
void foo(String a, int b)
{...}

Answers:



59

如您在java.lang.String类的Java Source中所见:

/**
 * Allocates a new <code>String</code> that contains characters from
 * a subarray of the character array argument. The <code>offset</code>
 * argument is the index of the first character of the subarray and
 * the <code>count</code> argument specifies the length of the
 * subarray. The contents of the subarray are copied; subsequent
 * modification of the character array does not affect the newly
 * created string.
 *
 * @param      value    array that is the source of characters.
 * @param      offset   the initial offset.
 * @param      count    the length.
 * @exception  IndexOutOfBoundsException  if the <code>offset</code>
 *               and <code>count</code> arguments index characters outside
 *               the bounds of the <code>value</code> array.
 */
public String(char value[], int offset, int count) {
    if (offset < 0) {
        throw new StringIndexOutOfBoundsException(offset);
    }
    if (count < 0) {
        throw new StringIndexOutOfBoundsException(count);
    }
    // Note: offset or count might be near -1>>>1.
    if (offset > value.length - count) {
        throw new StringIndexOutOfBoundsException(offset + count);
    }

    this.value = new char[count];
    this.count = count;
    System.arraycopy(value, offset, this.value, 0, count);
}

参数引用由<code></code>标签包围,这意味着Javadoc语法不提供任何执行此操作的方法。(我认为String.class是javadoc用法的一个很好的例子)。


5
<code> </ code>标记未引用特定参数。它正在将单词“ String”格式化为“看起来代码”文本。
Naxos84

46

引用方法参数的正确方法是这样的:

在此处输入图片说明


2
这不会对现有答案添加任何内容。请删除它。
suriv '17

27
它不仅回答了这个问题,而且还直观地解释了如何使用诸如Intellij之类的IDE用参数修改Javadoc。这对于正在寻找答案的搜索者很有用。
Eurig Jones,

1
在Eclipse上不起作用。但这仍然是一个不错的答案
Henrique de Sousa

2
这应该删除。想象不再存在。
user4504267 '17

2
@ user4504267图像至少在现在看起来不错。
ErikE

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.