Structure JavaDoc of Constructors

 class​ Inventory {
 
  List<Supply> supplies;
 
 /**
» * Constructor for a new Inventory.
  */
  Inventory() {
 this​(​new​ ArrayList<>());
  }
 
 /**
» * Another Constructor for a new Inventory.
  *
  * It is possible to add some supplies to the Inventory.
  */
  Inventory(Collection<Supply> initialSupplies) {
 this​.supplies = ​new​ ArrayList<>(initialSupplies);
  }
 }

There’s one special type of method in Java that you can’t assign a good and meaningful name to: constructors. They always have the same name as the class. They may have a clearer purpose than other methods (they always construct an object), but if you misuse them, those objects will be flawed. That’s why you have to explain ...

Get Java By Comparison now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.