Immutability

An immutable object no longer changes state after construction: final fields, no setters, and defensive copies for mutable fields. It is safe to share between parts of the program and between threads. String and the wrapper types are immutable; records are by default.

Example

final class Euro {
    private final long centimes;
    Euro(long c) { this.centimes = c; }
}

Related concepts

The whole glossary