java 如何将方法的 Javadoc 复制到其他方法的 Javadoc 中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3618185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can a method's Javadoc be copied into other method's Javadoc?
提问by java.is.for.desktop
I know that there is @inheritDoc, but it's only for methods which override others.
我知道有@inheritDoc,但它仅适用于覆盖其他方法的方法。
I have several classes with many delegatemethods (which do notoverride others).
我有几个带有许多委托方法的类(不会覆盖其他方法)。
Can their Javadoc be "inherited" (more exactly: copied)?
他们的 Javadoc 可以“继承”(更准确地说:复制)吗?
/** here I need the copy of wrappedMethod's Javadoc */
public void delegateMethod(Object param){
innerSomething.wrappedMethod(param);
}
采纳答案by Danny Thomas
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.
@link 或 @see 标签在这里是合适的。如果您要包装该方法,则它必须提供独特的行为,使其不适合重载或其他方式。
回答by DJClayworth
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.
但是,在代表的情况下,我多次遇到相同的问题。通常,您在委托给包私有委托的主类上有一个公共方法,该委托具有与主方法完全相同的行为。这里的解决方案很简单 - 记录主类,并将 @link 或 @see 放在委托类上。每个人都可以看到主类的文档。您可能还需要有关委托类的更详细的文档,例如实现细节。

