how can I make a javadoc link to a private field?
class Foo {
private String bar;
public String getBar() { return bar; }
}
{@link Foo#getBar()}
works.
{@link Foo#bar}
doesn't.
See Java Javadoc include Private; you still use the standard JavaDoc comment form but you must instruct the JavaDoc tool to generate the documentation for private members using the -private switch.
Private fields won't have Javadoc generated for them unless we explicitly pass the -private option to the Javadoc command.
Nope, you shouldn't write javadoc for private methods. End users don't have access to private fields or methods so there really isn't a point in providing javadoc for them. Private fields and methods are only meant for the developer.
Javadoc provides the @link inline tag for referencing the members in the Java classes. We can think of the @link tag as similar to the anchor tag in HTML, which is used to link one page to another via hyperlinks. Similar to the anchor tag, the path_to_member is the destination, and the label is the display text.
The syntax is fine, both the following work within a class (and there's no reason to link to a private field from a different class):
public class Demo {
private int num = 0;
/**
* Access field {@link Demo#num} / {@link #num} ...
*/
private void foo() { ... }
...
When generating the javadoc, e.g., via ant, just specify that private fields should be included (the default minimum access is "protected", not "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>
I think what you are writing in the comments is fine, you just need to tell JavaDoc to also include private fields in the documentation. JavaDoc has an option -private for this. Check this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With