2

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?

wvdz
  • 16,251
  • 4
  • 53
  • 90

2 Answers2

3

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()
*/
wvdz
  • 16,251
  • 4
  • 53
  • 90
1

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.

Kong
  • 8,792
  • 15
  • 68
  • 98
  • We just need `@inheritMethod` if type/name is the same, then reuse the comment. Maybe a plugin should work. – Leon Mar 26 '18 at 08:22