HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaCritical

How to reference a method in javadoc?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howreferencejavadocmethod

Problem

How can I use the @link tag to link to a method?

I want to change:

/**
 * 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()


to:

/**
 * 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()


but I don't know how to format the @link tag correctly.

Solution

You will find much information about JavaDoc at the Documentation Comment Specification for the Standard Doclet, including the information on the

{@link module/package.class#member label}

inline tag (that you are looking for). The corresponding example from the documentation is as follows

For example, here is a comment that refers to the getComponentAt(int, int) method:

Use the {@link #getComponentAt(int, int) getComponentAt} method.

The module/package.class part can be ommited if the referred method is in the current class.

Since JavaDoc also supports Markdown Content since Java 23 you can also use Markdown reference links (quote from the documentation):
The following all represent links to java.lang.Object#hashCode(), albeit with different text to be displayed:

[the default hashcode for an object][java.lang.Object#hashCode()]
[the default hashcode][Object#hashCode()] — no need for the fully qualified name in this case
[Object#hashCode()][] — using the collapsed form of a reference link
[Object#hashCode()] — using the shortcut form of a reference link


Other useful links about JavaDoc are:

  • JDK 25 Tool Specifications - The javadoc Command



  • JavaDoc Guide



  • How to Write Doc Comments for the Javadoc Tool

Context

Stack Overflow Q#5915992, score: 1293

Revisions (0)

No revisions yet.