有没有办法从方法文档正文中添加对一个或多个方法参数的引用? 类似的东西:
/**
* 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)
{...}
答案 0 :(得分:335)
据我所知,在阅读the docs for javadoc之后,没有这样的功能。
请勿按照其他答案中的建议使用<code>foo</code>
;你可以使用{@code foo}
。当你引用像{@code Iterator<String>}
这样的泛型类型时,这一点尤其有用 - 肯定看起来比<code>Iterator<String></code>
更好,不是吗!
答案 1 :(得分:57)
正如您在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用法的一个很好的例子。)
答案 2 :(得分:30)
答案 3 :(得分:10)
答案 4 :(得分:-3)
对于 2021 年,正确的方法是使用 @param
:
/**
* When {@param 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)
{...}
详情请参阅一些 javadoc 标签说明:https://idratherbewriting.com/java-javadoc-tags/