是否有一种方法可以从方法文档主体中添加对一个或多个方法参数的引用? 喜欢的东西:

/**
 * 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)
{...}

当前回答

正如你在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用法的一个很好的例子)。

其他回答

我想您可以编写自己的doclet或taglet来支持这种行为。

名为Taglet概述

Doclet概述

正如你在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用法的一个很好的例子)。

在阅读了javadoc的文档后,据我所知,没有这样的特性。

不要使用<code>foo</code>作为其他答案的建议;你可以使用{@code foo}。当你引用一个泛型类型,如{@code Iterator<String>}时,这一点尤其值得知道——当然比<code>Iterator&lt;String&gt;</code>好看,不是吗!

下面是如何在Eclipse Temurin JDK 8源代码中编写的:

看起来唯一的方法是或{@code},但它不是一个链接-它只是格式化。

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