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