When we use classes in Java it's very simple to add JavaDoc/comment for each class field/method:
class Product {
//Product unique identifier
private int id;
}
If we migrate these classes to Java records then it's unclear what is the the best practice to write comments/JavaDocs in this case:
record Product(int id, String name, double price) {
}
Because now all the fields are declared in one line.
id
,name
, andprice
in the second snippet are not fields, these are record components. Answer by Yassin already mentioned how to achieve it but just for the sake of completeness, here is how you do it:The following would be ignored by standard doclet:
If you have a field, then you can add Javadoc to it:
To add Javadoc to the canonical constructor, you can use compact style: