How to reuse javadoc for similar functions

谁说我不能喝 提交于 2019-12-10 10:38:18

问题


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?


回答1:


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()
*/



回答2:


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.



来源:https://stackoverflow.com/questions/23899353/how-to-reuse-javadoc-for-similar-functions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!