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

rip*_*234 303 java arguments javadoc

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

/**
 * 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)
{...}
Run Code Online (Sandbox Code Playgroud)

Kev*_*ion 353

据我所知,在阅读javadoc的文档后,没有这样的功能.

不要<code>foo</code>按照其他答案中的建议使用; 你可以使用{@code foo}.当你提到一个类似的泛型类型时,这一点尤其{@code Iterator<String>}有用 - 确定看起来比<code>Iterator&lt;String&gt;</code>不好,不是!

  • 怎么不可能在方法的文档中引用方法自己的参数。摇摆不定,Java! (11认同)
  • `@code` 标签在 [Javadoc - 标签描述](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/javadoc.html) 中进行了描述。请参阅[JDK8代码中的示例用法](http://hg.openjdk.java.net/jdk8u/jdk8u60/jdk/file/tip/src/share/classes/java/lang/String.java#l172)。 (2认同)

Las*_*ico 61

正如您在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);
}
Run Code Online (Sandbox Code Playgroud)

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

  • 这是旧的.使用{@code foo}记录字符串 (34认同)
  • <code> </ code>标记未引用特定参数.它将单词"String"格式化为"代码查找"文本. (2认同)

Eur*_*nes 39

引用方法参数的正确方法如下:

在此输入图像描述

  • 它不仅回答了这个问题,而且直观地解释了如何使用诸如Intellij之类的IDE来修改Javadoc.这对于正在寻找答案的搜索者非常有用. (22认同)
  • 尝试重构参数名称,intellij 不会更新此代码块。 (4认同)
  • 这不会对现有答案添加任何内容。请删除它。 (2认同)
  • 在 Eclipse 上它不起作用。但这仍然是一个很好的答案 (2认同)
  • 这应该删除.想象不再存在. (2认同)
  • @ user4504267图像看起来至少现在还不错。 (2认同)
  • 尽管图片很漂亮,请忽略这个答案并查看@kevin-bourrillion 接受的答案,因为它说要做同样的事情,但指出这只是一种解决方法,因为不存在这样的功能(......所以你不应该期望实际链接或用于重构以更新它等)。 (2认同)

jit*_*ter 10

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

Taglet概述

Doclet概述

  • 并向javadoc提出拉取请求:) (18认同)