Added
A billing application needs an immutable `InvoiceKey` used as a key in hash-based maps. It contains a customer identifier and a list of line identifiers. Callers may pass a mutable list and later mutate it, and the accessor must not let callers alter the key after construction. Equality and hash code must reflect the identifier and the list contents. Which implementation strategy is safest?
A final class with private final state and a defensive copy prevents subclassing and stops later changes to the caller's input from changing the key. Returning an unmodifiable view prevents mutation through the accessor, while value-based `equals` and `hashCode` must use the same identity components for correct hash-map behavior. Storing or returning the mutable list exposes the key to mutation. Implementing equality without a corresponding hash code violates the general contract. A static list is shared across invoices and cannot represent per-instance state.