How can a method's Javadoc be copied into other method's Javadoc?

旧巷老猫 提交于 2019-12-09 00:25:39

问题


I know that there is @inheritDoc, but it's only for methods which override others.

I have several classes with many delegate methods (which do not override others).

Can their Javadoc be "inherited" (more exactly: copied)?

/** here I need the copy of wrappedMethod's Javadoc */
public void delegateMethod(Object param){
  innerSomething.wrappedMethod(param);
}

回答1:


A @link or @see tag would be appropriate here. If you're wrapping the method, it must provide distinctive behavior which makes it unsuitable for overloading or otherwise.




回答2:


Sometimes it's actually a good thing to cut and paste documentation. 'Linking' documentation in some way, especially when there isn't in inheritance relationship, runs the risk that one of the methods will have it's behaviour changed somehow, making the linked documentation no longer valid.

However in the case of delegates I've had the same problem a number of times. Usually you have a public method on a main class delegating to a package-private delegate, which has exactly the same behaviour as the main method. Here the solution is simple - document the main class, and put the @link or @see on the delegate class. Everybody can see the main class' documentation. You will probably need to have more detailed documentation, such as implementation details, on the delegate class too.



来源:https://stackoverflow.com/questions/3618185/how-can-a-methods-javadoc-be-copied-into-other-methods-javadoc

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