I have a Java class with a generic type P. I want to document it in Javadoc. Normally I just do this:
/** * ... * @param <P> the type of publisher */
This shows up fine in actual Javadoc. However, CheckStyle is warning me that I need to document the type P because it renders <P> as a HTML paragraph. Also, the Eclipse formatter interprets it as a paragraph as well, so it messes up the formatting.
Is there a better way of documenting type parameters with type P? I know I can disable the Eclipse formatter to no longer auto format javadoc, but I'd rather not (and it wouldn't solve the checkstyle problem anyway).
I also know I can just rename P to something else, but given the number of generic types I am working with here, it would make things a lot less readable.
Your use of <P> to separate paragraphs will be in line with the rest of the Javadoc output.
This new tag allows the developer to explicitly specify what portion of the Javadoc comment appears in the "summary" rather than relying on Javadoc's default treatment looking for a period and space to demarcate the end of the summary portion of the comment.
Writing Javadoc Comments In general, Javadoc comments are any multi-line comments (" /** ... */ ") that are placed before class, field, or method declarations. They must begin with a slash and two stars, and they can include special tags to describe characteristics like method parameters or return values.
You can place JavaDoc comments in any of three different locations in a source file: Immediately before the declaration of a public class. Immediately before the declaration of a public field. Immediately before the declaration of a public method or constructor.
This is a bug in CheckStyle.
The official Javadoc documentation says that notation is correct:
Example of a type parameter of a class:
/** * @param <E> Type of element stored in a list */
If you're stuck with this version of CheckStyle, then the only way to satisfy both constraints is to rename your P
type parameter to something else.
FOR POSTERITY: Turns out Checkstyle handles it just fine. The problem is that the whitespace added by the Eclipse formatter made Checkstyle (reasonably) argue that the Javadoc was incorrect. I also found an existing bug report for this bug in Eclipse: https://bugs.eclipse.org/bugs/show_bug.cgi?id=121728
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With