如何在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
How to add reference to a method parameter in javadoc?
提问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<String></code>
, doesn't it!
不要<code>foo</code>
按照其他答案中的建议使用;你可以使用{@code foo}
. 当您引用泛型类型(例如{@code Iterator<String>}
-- 确实看起来比 更好<code>Iterator<String></code>
,不是吗!
回答by jitter
I guess you could write your own doclet or taglet to support this behaviour.
我想您可以编写自己的 doclet 或 taglet 来支持这种行为。
回答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 用法的一个很好的例子)。