Javadoc - 如何复制函数描述?

发布于 2024-10-27 09:18:34 字数 221 浏览 1 评论 0原文

我有两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一世旳自豪 2024-11-03 09:18:34

假设复制和粘贴对您不起作用,我相信惯例是使用 @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

琉璃梦幻 2024-11-03 09:18:34

简短的回答是你不能。习惯是使用 @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.

你与昨日 2024-11-03 09:18:34

由于具有不同类型参数的两个方法不能具有相同的描述。
但对于继承的方法,我们可以使用相同的描述。

继承的方法

对于继承的方法,您可以使用

{@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.

微凉 2024-11-03 09:18:34

你不想那样做。您希望第二个引用第一个。这就是@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.

埋葬我深情 2024-11-03 09:18:34

不要只使用 {@see ...},它具有不同的含义并且存在一些问题(例如不覆盖继承的文档)。

斯巴达 /** 请参阅:{@link ...}。 */ 更好。

然而,最好是添加更多的文字,而不仅仅是“See”。简要描述该方法的意图及其具体内容,并{@link ...}到详细解释完整合同的方法。这通常在 JDK 和其他库中完成,是一个很好的实践。

例如:

/**
 * Does something very important.
 * For details see {@link #doSomething(Integer)}.
 */

或:

/**
 * Does something very important.
 * Equivalent to calling {@link #doSomething(Integer) doSomething(0)}.
 */

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:

/**
 * Does something very important.
 * For details see {@link #doSomething(Integer)}.
 */

or:

/**
 * Does something very important.
 * Equivalent to calling {@link #doSomething(Integer) doSomething(0)}.
 */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文