java-docs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Java Documentation (Javadoc) Best Practices

Java 文档(Javadoc)最佳实践

  • Public and protected members should be documented with Javadoc comments.
  • It is encouraged to document package-private and private members as well, especially if they are complex or not self-explanatory.
  • The first sentence of the Javadoc comment is the summary description. It should be a concise overview of what the method does and end with a period.
  • Use
    @param
    for method parameters. The description starts with a lowercase letter and does not end with a period.
  • Use
    @return
    for method return values.
  • Use
    @throws
    or
    @exception
    to document exceptions thrown by methods.
  • Use
    @see
    for references to other types or members.
  • Use
    {@inheritDoc}
    to inherit documentation from base classes or interfaces.
    • Unless there is major behavior change, in which case you should document the differences.
  • Use
    @param <T>
    for type parameters in generic types or methods.
  • Use
    {@code}
    for inline code snippets.
  • Use
    <pre>{@code ... }</pre>
    for code blocks.
  • Use
    @since
    to indicate when the feature was introduced (e.g., version number).
  • Use
    @version
    to specify the version of the member.
  • Use
    @author
    to specify the author of the code.
  • Use
    @deprecated
    to mark a member as deprecated and provide an alternative.
  • 公共(public)和受保护(protected)成员应使用Javadoc注释进行文档化。
  • 建议同时对包私有(package-private)和私有(private)成员进行文档化,尤其是当它们逻辑复杂或无法自解释时。
  • Javadoc注释的第一句是摘要描述。它应该是对方法功能的简洁概述,并以句号结尾。
  • 使用
    @param
    来描述方法参数。描述以小写字母开头,且不以句号结尾。
  • 使用
    @return
    来描述方法返回值。
  • 使用
    @throws
    @exception
    来记录方法抛出的异常。
  • 使用
    @see
    来引用其他类型或成员。
  • 使用
    {@inheritDoc}
    来继承基类或接口的文档。
    • 除非存在重大行为变更,这种情况下你应该记录差异内容。
  • 使用
    @param <T>
    来标注泛型类型或方法中的类型参数。
  • 使用
    {@code}
    来标记内联代码片段。
  • 使用
    <pre>{@code ... }</pre>
    来标记代码块。
  • 使用
    @since
    来指明特性的引入时间(例如:版本号)。
  • 使用
    @version
    来指定成员的版本。
  • 使用
    @author
    来指定代码的作者。
  • 使用
    @deprecated
    来标记某个成员已过时,并提供替代方案。