id
, name
, and price
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:
/**
* A very complex Product description.
*
* @param id Product identifier; appears in "Record Components".
* @param name Product name appears; in "Record Components".
* @param price Product price; appears in "Record Components".
*/
public record Product(int id, String name, double price){}
The following would be ignored by standard doclet:
public record Product(
/**
* This comment would be ignored.
*/
int id,
/*
* Ignored
*/
String name,
// Ignored
double price) {}
If you have a field, then you can add Javadoc to it:
public record Product(...) {
/**
* Max Product price, appears in "Field Summary".
* <p>
* Appears in "Field Details".
*/
public static final double MAX_PRICE = Integer.MAX_VALUE >> 2;
}
To add Javadoc to the canonical constructor, you can use compact style:
public record Product(...) {
/**
* Product's compact canonical constructor, appears in "Constructor Summary".
* <p>
* In "Constructor Details".
*
* @param id Product identifier, appears in "Constructor Details"
* not in "Record Components".
* @param name Product name, appears in "Constructor Details"
* not in "Record Components".
* @param price Product price, appears in "Constructor Details"
* not in "Record Components".
* @throws IllegalArgumentException Allowed price range
* ({@code 0.0D}, {@link Product#MAX_PRICE}]
*/
public Product {
if (price <= 0 || price > MAX_PRICE) throw new IllegalArgumentException();
}
}