Javadoc see or link?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In Java documentation, the @see and {@link} tags are pivotal in creating comprehensive and navigable API documentation. Both are utilized within Javadoc comments and serve to provide references to other elements within the code or even external documentation. However, they have distinct differences in their usage and behavior.
Understanding @see and {@link}
@see
The @see tag is used to create a "See Also" reference at the end of a Javadoc comment. This reference points to a related class, method, or field. Typically, the @see tag is used to provide a general reference rather than inline text.
Syntax
The tag takes the fully qualified name of a class, method, or field. When used, it generates a hyperlink in the generated HTML documentation, which directs the reader to the specified reference.
Example
Suppose we have the following class with a method reference in a Javadoc comment:
This creates a link in the generated Javadoc pointing to the ArrayList class in the standard Java library, suggesting to the reader that ArrayList is relevant to the current class discussion.
{@link}
In contrast, the {@link} tag is used to create an inline link within a Javadoc comment. It allows you to hyperlink a word or phrase within the main body of text itself, making it more fluid for the reader.
Syntax
This tag also takes the fully qualified name of a class, method, or field. However, it allows the reader to click on the embedded reference in the documentation where it appears directly within a paragraph or list.
Example
Consider the following usage within a method comment:
In this example, "HashMap" within the comment body will be an interactive link pointing to its API documentation.
Key Differences
Here's a summarized comparison between @see and {@link}:
| Aspect | @see | {@link} |
| Purpose | Generates a "See Also" list | Inline text hyperlink |
| Usage | Stand-alone, post-description | Within descriptive text |
| Appearance | At the end of the Javadoc comment block | Inline with other text |
| Linking style | List of references at the end of the Javadoc comment | Embedded within sentences |
| Use case | Broad references | Contextual, specific references |
Additional Considerations
Alternative Tag: {@linkplain}
- Purpose: Similar to
{@link}but generates plain-text links. - Use Case: When you want a link in the Javadoc without the default link style (useful for when style formatting needs customization).
Creating External Links
For cases when you want to refer to an external source or a non-public member, you may use HTML anchor tags directly within Javadocs:
Best Practices
- Choose Appropriately: Use
@seewhen you need to suggest additional reading or related classes. Use{@link}to create more engaging and well-connected documentation. - Syntax Precision: Ensure that names are fully qualified if they are not within the same package or if ambiguity might arise.
- Documentation Quality: Always ensure that the linked references enhance understanding rather than just being presentational decorations.
These tags are essential tools in a developer's toolkit for creating robust and navigable documentation, substantially aiding in the maintenance and usability of the code for others accessing it. By understanding when and how to use each, developers can create clearer, more informative Javadocs that contribute to better code literacy and usability.

