Java enterprise capstone
Validate a domain quantity
Validation happens at construction, not after state is modified.
Formal Syntax & Structure
java syntaxjava
new Quantity(value)Working Example
Example Snippetjava
public class Main { record Quantity(int value) { Quantity { if(value<1 || value>100) throw new IllegalArgumentException("quantity"); } } public static void main(String[] args) throws Exception { System.out.println(new Quantity(3).value()); }}