Javadoc @see or {@link}?

不想你离开。 提交于 2019-11-28 13:43:21

问题


Could someone tell me the difference between javadoc @see and {@link}?

Or rather, when to use which of them?


回答1:


The official guidelines on this are pretty clear.

The functional differences are:

  • {@link} is an inline link and can be placed wherever you like
  • @see creates its own section

In my opinion, {@link} is best used when you literally use a class, field, constructor or method name in your description. The user will be able to click through to the javadoc of what you've linked.

I use the @see annotation in 2 cases:

  • Something is very relevant but not mentioned in the description.
  • I refer to the same thing multiple times in the description, and it is used as a replacement for multiple links to the same.

I based this opinion on randomly checking out documentation for a great variety of things in the standard library.




回答2:


@see creates an isolated line in the Javadocs. {@link} is for embedding within text.

I use @see when it's a related entity but I don't refer to it in the expository text. I use links within text when there's tight coupling, or (I feel) it's likely the reader would benefit from the navigation hint, e.g., you'll need to reference it directly.




回答3:


There's another reference (deprecation section) same official docs to prefer {@link} over @see (since Java 1.2):

For Javadoc 1.2 and later, the standard format is to use @deprecated tag and the in-line {@link} tag. This creates the link in-line, where you want it. For example:

For Javadoc 1.1, the standard format is to create a pair of @deprecated and @see tags. For example:



来源:https://stackoverflow.com/questions/10097199/javadoc-see-or-link

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