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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1667212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:55:38  来源:igfitidea点击:

How to add reference to a method parameter in javadoc?

javaargumentsjavadoc

提问by ripper234

Is there a way to add references to one or more of a method's parameters from the method documentation body? Something like:

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

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

采纳答案by Kevin Bourrillion

As far as I can tell after reading the docs for javadocthere is no such feature.

据我阅读javadoc 的文档后我知道没有这样的功能。

Don't use <code>foo</code>as recommended in other answers; you can use {@code foo}. This is especially good to know when you refer to a generic type such as {@code Iterator<String>}-- sure looks nicer than <code>Iterator&lt;String&gt;</code>, doesn't it!

不要<code>foo</code>按照其他答案中的建议使用;你可以使用{@code foo}. 当您引用泛型类型(例如{@code Iterator<String>}-- 确实看起来比 更好<code>Iterator&lt;String&gt;</code>,不是吗!

回答by jitter

I guess you could write your own doclet or taglet to support this behaviour.

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

Taglet Overview

Taglet 概述

Doclet Overview

Doclet 概述

回答by Lastnico

As you can see in the Java Source of the java.lang.String class:

正如您在 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);
}

Parameter references are surrounded by <code></code>tags, which means that the Javadoc syntax does not provide any way to do such a thing. (I think String.class is a good example of javadoc usage).

参数引用被<code></code>标签包围,这意味着 Javadoc 语法没有提供任何方法来做这样的事情。(我认为 String.class 是 javadoc 用法的一个很好的例子)。

回答by Eurig Jones

The correct way of referring to a method parameter is like this:

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

enter image description here

在此处输入图片说明