How to link javadoc to private field?

JavaJavadoc

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

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>

Solution 2 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmembersoundView Question on Stackoverflow
Solution 1 - JavamichaelView Answer on Stackoverflow
Solution 2 - Javadamix911View Answer on Stackoverflow