JavaDoc 中 @see 的用法?

发布于 2024-10-17 10:41:09 字数 348 浏览 5 评论 0原文

处理 JavaDocs 时什么时候使用 @see ?它的用途是什么?

例如,如果 MethodA 调用 MethodB 那么我是否必须将 @see 放入 MethodB 的 javadoc 并引用 < code>MethodA 因为这就是调用它的方法,或者我是否必须从 MethodA 引用 MethodB 因为它正在调用它。我在 Oracle 网站上读过有关 @see 的内容,在我看来,它非常模糊,它表示“另请参阅”,但实际上并不是什么意思!

When do I use @see when dealing with JavaDocs? What is its usage?

For example if MethodA calls MethodB then do I have to put @see in MethodB's javadoc and reference MethodA because that is what called it, or do I have to put a reference to MethodB from MethodA because it's calling it. I've read the stuff about @see on the Oracle website and it seems to me to be incredibly vague, it says it means "see also" but not really what that means!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

篱下浅笙歌 2024-10-24 10:41:09

是的,这很模糊。

只要对您的方法文档的读者查看其他方法可能有用,您就应该使用它。如果你的 methodA 的文档说“与 methodB 类似,但是......”,那么你肯定应该添加一个链接。

@see 的替代方案是内联 {@link ...} 标记:

/**
 * ...
 * Works like {@link #methodB}, but ...
 */

当 methodA 调用 methodB 的事实是一个实现细节并且与来自的方法没有真正的关系时在外面,您不需要此处的链接。

Yeah, it is quite vague.

You should use it whenever it may be useful for readers of the documentation of your method to also look at some other method. If the documentation of your methodA says "Works like methodB but ...", then you surely should put a link.

An alternative to @see would be the inline {@link ...} tag:

/**
 * ...
 * Works like {@link #methodB}, but ...
 */

When the fact that methodA calls methodB is an implementation detail and there is no real relation from the outside, you don't need a link here.

谷夏 2024-10-24 10:41:09

@see 标记与 @link 标记略有不同,
在某些方面受到限制,而在其他方面则更加灵活。
以下示例来自 Eclipse:

不同的 JavaDoc 链接类型
不同的JavaDoc链接类型

  1. 显示成员名称以便更好的学习,并且是可重构的;通过重构重命名时名称会更新
  2. 可重构且可定制;显示您的文本而不是成员名称
  3. 显示名称,可重构
  4. 可重构,可自定义
  5. 一个相当平庸的组合,即:
  • 可重构、可自定义,并保留在另请参阅部分
  • 显示良好在 Eclipse 悬停时
  • 显示链接标签及其生成时的格式

The @see tag is a bit different than the @link tag,
limited in some ways and more flexible in others.
The following examples are from Eclipse:

different JavaDoc link types
Different JavaDoc link types

  1. Displays the member name for better learning, and is refactorable; the name will update when renaming by refactor
  2. Refactorable and customizable; your text is displayed instead of the member name
  3. Displays name, refactorable
  4. Refactorable, customizable
  5. A rather mediocre combination that is:
  • Refactorable, customizable, and stays in the See Also section
  • Displays nicely in the Eclipse hover
  • Displays the link tag and its formatting when generated ????
  • When using multiple @see items, commas in the description make the output confusing
  1. Completely illegal; causes unexpected content and illegal character errors in the generator

See the results below:

JavaDoc generation results with different link types
JavaDoc generation results with different link types

Best regards.

九命猫 2024-10-24 10:41:09

@see 有用的一个很好的例子是实现或重写接口/抽象类方法。该声明将包含详细说明该方法的 javadoc 部分,并且重写/实现的方法可以使用 @see 标记来引用基础标记。

相关问题:
使用 @see 编写正确的 javadoc?

Java SE 文档:@see

A good example of a situation when @see can be useful would be implementing or overriding an interface/abstract class method. The declaration would have javadoc section detailing the method and the overridden/implemented method could use a @see tag, referring to the base one.

Related question:
Writing proper javadoc with @see?

Java SE documentation: @see

音盲 2024-10-24 10:41:09

@see 对于有关 API 中相关方法/类的信息很有用。它将生成文档中引用的方法/代码的链接。当有相关代码可以帮助用户了解如何使用 API 时,请使用它。

@see is useful for information about related methods/classes in an API. It will produce a link to the referenced method/code on the documentation. Use it when there is related code that might help the user understand how to use the API.

毁虫ゝ 2024-10-24 10:41:09

我使用 @see 来注释接口实现类的方法,其中该方法的描述已在接口的 javadoc 中提供。当我们这样做时,我注意到 Eclipse 会提取接口的文档,即使我在代码完成期间查找实现参考上的方法也是如此

I use @see to annotate methods of an interface implementation class where the description of the method is already provided in the javadoc of the interface. When we do that I notice that Eclipse pulls up the interface's documentation even when I am looking up method on the implementation reference during code complete

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文