如何使用标记链接到方法?@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
网友回答:
javadoc 文档@link部分中的一般格式为:
同一类中的方法:
/** See also {@link #myMethod(String)}. */
void foo() { ... }
不同类中的方法,可以在同一包中,也可以导入:
/** See also {@link MyOtherClass#myMethod(String)}. */
void foo() { ... }
方法在不同的包中且未导入:
/** See also {@link com.mypackage.YetAnotherClass#myMethod(String)}. */
void foo() { ... }
链接到方法的标签,采用纯文本而不是代码字体:
/** See also this {@linkplain #myMethod(String) implementation}. */
void foo() { ... }
方法调用链,如您的问题所示。我们必须为指向此类外部方法的链接指定标签,否则我们得到 .但是这些标签在重构过程中可能很脆弱 — 请参阅下面的“标签”。getFoo().Foo.getBar().Bar.getBaz()
/**
* A convenience method, equivalent to
* {@link #getFoo()}.{@link Foo#getBar() getBar()}.{@link Bar#getBaz() getBaz()}.
* @return baz
*/
public Baz fooBarBaz()
自动重构可能不会影响标签。这包括重命名方法、类或包;并更改方法签名。
因此,仅当您需要与默认值不同的文本时,才提供标签。
例如,您可以从人类语言链接到代码:
/** You can also {@linkplain #getFoo() get the current foo}. */
void setFoo( Foo foo ) { ... }
或者,你可以从代码示例链接,其中包含与默认值不同的文本,如上文“方法调用链”下所示。但是,在 API 不断发展时,这可能很脆弱。
如果方法签名包含参数化类型,请在 javadoc @link中擦除这些类型。例如:
int bar( Collection<Integer> receiver ) { ... }
/** See also {@link #bar(Collection)}. */
void foo() { ... }
网友回答:
您可以在标准 Doclet 的文档注释规范中找到有关 JavaDoc 的大量信息,包括有关
{@link module/package.class#Member label}
标记(您正在寻找的)。文档中的相应示例如下
例如,下面是一个引用 getComponentAt(int, int) 方法的注释:
Use the {@link #getComponentAt(int, int) getComponentAt} method.
如果引用的方法位于当前类中,则可以省略该部件。module/package.class
关于JavaDoc的其他有用链接是:
网友回答:
您可以使用来执行此操作:@see
样本:
interface View {
/**
* @return true: have read contact and call log permissions, else otherwise
* @see #requestReadContactAndCallLogPermissions()
*/
boolean haveReadContactAndCallLogPermissions();
/**
* if not have permissions, request to user for allow
* @see #haveReadContactAndCallLogPermissions()
*/
void requestReadContactAndCallLogPermissions();
}
模板简介:该模板名称为【如何在 javadoc 中引用方法?】,大小是暂无信息,文档格式为.编程语言,推荐使用Sublime/Dreamweaver/HBuilder打开,作品中的图片,文字等数据均可修改,图片请在作品中选中图片替换即可,文字修改直接点击文字修改即可,您也可以新增或修改作品中的内容,该模板来自用户分享,如有侵权行为请联系网站客服处理。欢迎来懒人模板【Java】栏目查找您需要的精美模板。