2009-11-03 29 views
247

有没有办法从方法文档体中添加对一个或多个方法参数的引用? 喜欢的东西:如何在javadoc中添加对方法参数的引用?

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

回答

290

据我所知,在阅读the docs for javadoc后就没有这样的特征。

请勿使用<code>foo</code>按照其他答案中的建议;你可以使用{@code foo}。当你提到一个通用类型时,这是特别好的,例如{@code Iterator<String>} - 确实看起来比<code>Iterator&lt;String&gt;</code>好看,不是吗?

53

正如你在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使用的一个很好的例子)。

+22

这是旧的。字符串被记录为{@code foo} – 2016-02-02 08:38:51

+2

标记未引用特定参数。它将单词“字符串”格式化为“代码查看”文本。 – Naxos84 2017-03-09 06:01:22

10

提到的方法参数的正确的方法是这样的:

enter image description here

+0

这不会对现有答案添加任何内容。请删除它。 – suriv 2017-01-23 20:31:04

+7

它不仅回答了问题,而且它直观地解释了如何使用IDE(如Intellij)通过参数修改Javadoc。这对于正在寻找答案的搜索者很有用。 – 2017-04-07 23:32:57

+0

在Eclipse上它不起作用。但这是一个很好的答案,但应该删除 – 2017-08-08 09:38:06

相关问题