Solution (source code)

= Solution

An immutable library value such as `java.lang.String` can be a <final class in Java>. No class can extend it, so a client receiving a `String` cannot secretly receive a subclass that changes the behavior of its methods. This protects assumptions about value semantics in code using strings as keys or trusted identifiers.

\b[The benefit is a closed implementation contract.] Without `final`, subclasses might override methods inconsistently or introduce behavior incompatible with the library's intended guarantees. Making a class final does not by itself make its fields immutable; a correct immutable implementation also controls its state. The cost is that clients cannot customize it by inheritance and must instead use composition or a different abstraction.