Javadoc - 如何复制函数描述?
我有两个 Java 函数:
/**
* Do something with param
*/
public String doSomething(String param) {...};
/**
* ...
*/
public String doSomething(Integer param) {...};
如何使第二个函数的描述显示第一个函数的精确副本?
I have two Java functions:
/**
* Do something with param
*/
public String doSomething(String param) {...};
/**
* ...
*/
public String doSomething(Integer param) {...};
How can I make the second function's description to show an exact copy of the first function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
假设复制和粘贴对您不起作用,我相信惯例是使用 @see 标签来引用另一种方法,该方法将提供更多详细信息。
在您的示例中, doSomething(Integer param) 将有一个引用 String 版本的 @see 标记。
维基百科有一些示例, http://en.wikipedia.org/wiki/Javadoc
与 javadoc 的 oracle 站点一样工具 http://www.oracle.com/technetwork/java/javase /documentation/index-137868.html#multiple@see
Assuming copy and paste won't work for you, I believe the convention is to use the @see tag to refer to another method which will give greater detail.
In your example the doSomething(Integer param) would have an @see tag referring to the String version.
Wikipedia has some examples, http://en.wikipedia.org/wiki/Javadoc
As does the oracle site for the javadoc tool http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#multiple@see
简短的回答是你不能。习惯是使用
@see
指令或简单地复制粘贴。如果您要子类化,则可以将 javadoc 放在接口级别上来实现您想要的。
The short answer is you can't. Customary is to make use of the
@see
directive or simply copy pasting.If you are subclassing you can put the javadoc on the interface level instead to achieve what you want.
由于具有不同类型参数的两个方法不能具有相同的描述。
但对于继承的方法,我们可以使用相同的描述。
继承的方法
对于继承的方法,您可以使用
{@inheritDoc}
它从重写的方法复制描述。
As two methods with different type params can't have the same description.
But for inherited method we can use same description.
inherited method
For inherited method u can use
{@inheritDoc}
It copies the description from the overridden method.
你不想那样做。您希望第二个引用第一个。这就是@see 的用途。您永远不想重复文档,原因与您的第二个方法调用第一个方法而不是包含其代码的副本相同。
You don't want to do that. You want the second one to refer to the first one. That's what @see is for. You never want to repeat documentation, for the same reason that your second method calls the first method instead of containing a copy of its code.
不要只使用
{@see ...}
,它具有不同的含义并且存在一些问题(例如不覆盖继承的文档)。斯巴达
/** 请参阅:{@link ...}。 */
更好。然而,最好是添加更多的文字,而不仅仅是“See”。简要描述该方法的意图及其具体内容,并
{@link ...}
到详细解释完整合同的方法。这通常在 JDK 和其他库中完成,是一个很好的实践。例如:
或:
Don't just use
{@see ...}
, which has a different meaning and has some problems (like not overriding inherited documentation).A spartan
/** See: {@link ...}. */
is better.However, best is to add a bit more text than just "See". Briefly describe the intent of this method and what is specific to it, and
{@link ...}
to a method which explains the full contract in detail. This is often done in the JDK and other libraries and is a good practice.Eg:
or: