如何链接 javadoc 到私有字段?

如何建立私有字段的 javadoc 链接?

class Foo {
private String bar;
public String getBar() { return bar; }
}

{@link Foo#getBar()}成功了。

{@link Foo#bar}没有。

93889 次浏览

我认为您在评论中写的内容很好,您只需要告诉 JavaDoc 在文档中也包含私有字段。JavaDoc 为此提供了一个选项-private。检查 这个答案

这种语法很好,在一个类中有以下两种工作(没有理由从不同的类链接到一个私有字段) :

public class Demo {
private int num = 0;
/**
* Access field {@link Demo#num} / {@link #num}  ...
*/
private void foo() { ... }
...

当生成 javadoc 时,例如,通过 ant,只需指定应该包含私有字段(默认的最小访问权限是“ protected”,而不是“ private”) :

<target name="javadoc" depends="compile" description="gen javadoc">
<javadoc destdir="build/docs"
author="true"
version="true"
use="true"
access="private"
windowtitle="Demo API">


<fileset dir="src/main" defaultexcludes="yes">
<include name="com/**"/>
</fileset>


<doctitle><![CDATA[<h1>Test</h1>]]></doctitle>
<link offline="true" href="http://download.oracle.com/javase/6/docs/api/" packagelistLoc="doc"/>
</javadoc>
</target>