March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | 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 ...
Read now
Unlock full access