immutability
7 tutorials tagged “immutability”.
- Immutable Collections in JavaCreate unmodifiable lists, sets and maps with List.of, Set.of, Map.of, Map.ofEntries and copyOf. Learn their rules, benefits and common errors.
- Unmodifiable vs Immutable CollectionsAn unmodifiable view blocks changes through itself but still shows changes to the original; an immutable collection never changes. Learn the difference.
- Compact Constructors in RecordsValidate, normalize and defensively copy record data in a compact constructor, add extra constructors with this(...), and avoid the common errors.
- Defensive Copying in JavaProtect an object's internals from callers: copy mutable inputs in constructors and outputs in getters, with lists, arrays and dates as examples.
- How to Create an Immutable Class in JavaObjects that can never change after creation: the rules for an immutable class, a Money example, why String is immutable, and the benefits.
- Records in JavaOne line declares an immutable data class: what a record generates, how to add methods, the rules, shallow immutability, and when to use one.
- Why String Is Immutable in JavaA String can never change after it's created. What that means in code, the five reasons Java's designers chose it, and its one cost.