wvdz
wvdz

Reputation: 16651

How to reuse javadoc for similar functions

Let's say I have the following function:

/**
 * Thorough explanation
 *
 */
public void somethingImportant(String parameter)
{
   (...)
}

Now for convenience, I add the following function:

public void somethingImportant()
{
   somethingImportant(null);
}

The javadoc for both functions should be next to identical. Perhaps the only difference is that the first function has an extra line describing what parameter does.

Is there any way to avoid simply copying the existing javadoc, and instead reusing it?

Upvotes: 2

Views: 2281

Answers (2)

Social_Engineerer
Social_Engineerer

Reputation: 108

What about using @see tag and pointing to the original, non-overloaded method? Then in the overloaded method you can just use the @param value.

/**
*@see #yourMethod()
*/

Upvotes: 4

Kong
Kong

Reputation: 9596

This sought of functionality unfortunately isn't supported by JavaDoc. Instead what I do is fully document the method with the most parameters, then link my defaulting methods:

/**
 * {@code parameter} defaults to null.
 *
 * @see MyClass#somethingImportant(String)
 */
public void somethingImportant()

As an aside; if the methods you are docing are implementations of an interface or an override you can use the {@inheritDoc} tag.

Upvotes: 1

Related Questions