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

本文翻译自:How to add reference to a method parameter in javadoc?

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

#1楼

参考:https://stackoom.com/question/6ziW/如何在javadoc中添加对方法参数的引用


#2楼

I guess you could write your own doclet or taglet to support this behaviour. 我想你可以编写自己的doclet或taglet来支持这种行为。

Taglet Overview Taglet概述

Doclet Overview Doclet概述


#3楼

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. 参数引用由<code></code>标记包围,这意味着Javadoc语法不提供任何方法来执行此类操作。 (I think String.class is a good example of javadoc usage). (我认为String.class是javadoc用法的一个很好的例子)。


#4楼

As far as I can tell after reading the docs for javadoc there is no such feature. 据我所知,在阅读javadoc的文档后,没有这样的功能。

Don't use <code>foo</code> as recommended in other answers; 不要像其他答案中推荐的那样使用<code>foo</code> ; you can use {@code foo} . 你可以使用{@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 Iterator<String>}类的泛型类型时,这一点尤其<code>Iterator&lt;String&gt;</code> - 确实看起来比<code>Iterator&lt;String&gt;</code>更好,不是吗!


#5楼

The correct way of referring to a method parameter is like this: 引用方法参数的正确方法如下:

在此输入图像描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值