Joe Soltzberg

22%
Flag icon
The package-private mutable companion class approach works fine if you can accurately predict which complex operations clients will want to perform on your immutable class. If not, then your best bet is to provide a public mutable companion class. The main example of this approach in the Java platform libraries is the String class, whose mutable companion is StringBuilder (and its obsolete predecessor, StringBuffer).
Brian
· Flag
Brian
and then you restrict the operations available on the mutable companion class to just the manipulations needed, leaving the read operations to the immutable class? i remember using StringBuffer extens…
Effective Java
Rate this book
Clear rating
Open Preview