In Javadoc, the @return
tag is used to document the return value of a method. It is not strictly necessary to duplicate information in the @return
tag comment if the method's return value is already well-documented in the method's description or if the return value is self-explanatory. However, providing additional information in the @return
tag comment can be helpful in clarifying the purpose or behavior of the return value, especially if it is not immediately obvious from the method's signature.
Here are some guidelines to consider when using the @return
tag:
Document when necessary: If the return value requires additional explanation or context that cannot be easily inferred from the method signature, it's a good practice to provide a brief description in the @return
tag comment.
Avoid redundancy: Avoid duplicating information that is already present in the method's description or in other parts of the documentation. Redundant documentation can make the code harder to maintain and read.
Be concise: Keep the @return
tag comment concise and to the point. Provide just enough information to clarify the return value's purpose or behavior.
Here's an example:
/** * Retrieves the user's age. * * @return The user's age as an integer. */ public int getAge() { return age; }
In this example, the @return
tag comment is not strictly necessary because the return value is an integer, and it is already clear from the method name and signature that the method returns the user's age. However, it can still be helpful for documentation completeness and clarity.
In summary, while it's not always necessary to duplicate information in the @return
tag comment, it can be beneficial to provide additional context or explanation when it enhances the understanding of the method's behavior or return value. Ultimately, the decision to include a @return
tag comment should be based on whether it adds value to the documentation.
color-detection spring-security string-length syntax-highlighting system.diagnostics screen-orientation mysql-json parameter-passing requiredfieldvalidator stm32f1