Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference another method of the same class in Javadoc?

Tags:

java

javadoc

Suppose your class has 2 methods:

contains() and containsSame() 

The distinction between them is subtle and you'd like to mention it as part of Javadoc

In Javadoc, how can you reference a method in the same class, by name?

like image 593
James Raitsev Avatar asked Jun 05 '12 12:06

James Raitsev


People also ask

How do you reference another method in Javadoc?

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.

How do I add a method to a Javadoc?

Place the caret at the declaration in the editor, press Alt+Enter , and select Add Javadoc from the list.

What does @SEE mean in Javadoc?

We can use the @see and @link tag multiple times in a class, package, or method. The @see tag declares references that point to an external link, class, or method. The @link tag can also be used multiple times for declaring inline links or in contrast with other block tags.

What is @since in Javadoc?

Specify the product version when the Java name was added to the API specification (if different from the implementation). For example, if a package, class, interface or member was added to the Java 2 Platform, Standard Edition, API Specification at version 1.2, use: /** * @since 1.2 */


1 Answers

Use the @link inline tag, and refer to the method with a leading #.

/**  * ...  * This method is similar to {@link #contains()}, with the following differences:  * ...  */ public boolean containsSame();   /**  * This method does ...  */ public boolean contains(); 

This example only works if there is actually a contains() method which has no arguments (which, actually, seems to be not that useful). If you have only a contains method with arguments, then either write the argument types in the parentheses:

/**  * ...  * This method is similar to {@link #contains(Element)}, with the following differences:  * ...  */ public boolean containsSame(Element e);  /**  * This method does ...  */ public boolean contains(Element e); 

Or you can omit the parentheses completely:

/**  * ...  * This method is similar to {@link #contains}, with the following differences:  * ...  */ public boolean containsSame(Element e);  /**  * This method does ...  */ public boolean contains(Element e); 

If you have several methods named contains (with different parameter lists), this version can't decide which one to use (the link will jump to any of them, hopefully they are all together and do similar things).

like image 178
Paŭlo Ebermann Avatar answered Sep 21 '22 12:09

Paŭlo Ebermann