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

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).

Leave a Comment