如何使用 @link
标记链接到方法?
我想改变
/**
* Returns the Baz object owned by the Bar object owned by Foo owned by this.
* A convenience method, equivalent to getFoo().getBar().getBaz()
* @return baz
*/
public Baz fooBarBaz()
至
/**
* Returns the Baz object owned by the Bar object owned by Foo owned by this.
* A convenience method, equivalent to {@link getFoo()}.{@link getBar()}.{@link getBaz()}
* @return baz
*/
public Baz fooBarBaz()
但我不知道如何正确格式化 @link
标签 .
3 回答
你可以使用
@see
来做到这一点:样品:
您可以在Documentation Comment Specification for the Standard Doclet找到有关JavaDoc的更多信息,包括有关的信息
标签(您正在寻找) . 文档中的相应示例如下
如果引用的方法在当前类中,则可以省略
package.class
部分 .关于JavaDoc的其他有用链接是:
JavaDoc Tool Reference
JavaDoc Guide
How to Write Doc Comments for the Javadoc Tool
@link section of the javadoc documentation的一般格式为:
例子
Method in the same class:
Method in a different class, 在同一个包中或导入:
Method in a different package 并且未导入:
Label linked to method, in plain text 而不是代码字体:
A chain of method calls, 如你的问题所示 . 我们必须为这个类之外的方法的链接指定标签,否则我们得到
getFoo().Foo.getBar().Bar.getBaz()
. 但这些标签可能很脆弱;见下面的"Labels" .标签
Automated refactoring may not affect labels. 这包括重命名方法,类或包;并更改方法签名 .
Therefore, provide a label only if you want different text than the default.
例如,您可以从人类语言链接到代码:
或者您可以从代码示例链接到不同于默认值的文本,如上面“方法调用链”中所示 . 但是,当API不断发展时,这可能很脆弱 .
类型擦除和#member
如果方法签名包含参数化类型,请在javadoc @link中使用这些类型的擦除 . 例如: