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

aiazj4mn  于 2021-07-05  发布在  Java
关注(0)|答案(4)|浏览(412)

有没有办法从方法文档体中添加对一个或多个方法参数的引用?比如:

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

kr98yfug1#

据我所知,在阅读了javadoc的文档之后,没有这样的特性。
不要使用 <code>foo</code> 如其他答案所建议的那样;你可以用 {@code foo} . 当您引用泛型类型(如 {@code Iterator<String>} --当然看起来比 <code>Iterator&lt;String&gt;</code> ,不是吗!

rfbsl7qr

rfbsl7qr2#

在java.lang.string类的java源代码中可以看到:

/**
 * 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用法的一个很好的例子)。

fnatzsnv

fnatzsnv3#

我想你可以写你自己的doclet或taglet来支持这种行为。
taglet概述
doclet概述

ca1c2owp

ca1c2owp4#

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

相关问题