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.
You will find much information about JavaDoc at the Documentation Comment Specification for the Standard Doclet, including the information on the
tag (that you are looking for). The corresponding example from the documentation is as follows
The
package.class
part can be ommited if the referred method is in the current class.Other useful links about JavaDoc are:
you can use
@see
to do that:sample:
The general format, from the @link section of the javadoc documentation, is:
Examples
Method in the same class:
Method in a different class, either in the same package or imported:
Method in a different package and not imported:
Label linked to method, in plain text rather than code font:
A chain of method calls, as in your question. We have to specify labels for the links to methods outside this class, or we get
getFoo().Foo.getBar().Bar.getBaz()
. But these labels can be fragile; see "Labels" below.Labels
Automated refactoring may not affect labels. This includes renaming the method, class or package; and changing the method signature.
Therefore, provide a label only if you want different text than the default.
For example, you might link from human language to code:
Or you might link from a code sample with text different than the default, as shown above under "A chain of method calls." However, this can be fragile while APIs are evolving.
Type erasure and #member
If the method signature includes parameterized types, use the erasure of those types in the javadoc @link. For example: