The motivation for this was my answer ("Wishful thinking") to an earlier question on StringBuilder best-practices. If StringBuilder was extensible, then domain-specific subclasses could extend its fluent interface, which would tighten up code where a StringBuilder gets passed around to a lot of methods that build parts of a larger string.
I'm considering suggesting something - maybe a StringBuilder delegate - to the Guava folks.
What additional purpose does it serve for StringBuilder to be final, as opposed to just having final methods?
If all methods are final then the current behaviour of StringBuilder cannot be modified. Subclasses of it must add either unconnected behaviour (which is inherently bad design) or new functionality which uses the old, such as convenience methods. If you want to do the latter it is probably better to have a class that provides the relevant functionality but contains a StringBuilder rather than extends it. As Joshua Bloch says, "prefer containment over inheritence". In short, if all methods are final there is no good reason to extend the class, and you may as well make it final too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With