Brian Goetz mentioned in a recent article on InfoQ that making String
final
caused problems:
A good example where we pay for this tension is String; it is critical to the security of the platform that strings be immutable, and therefore String cannot be publicly extensible -- but it would be quite convenient for the implementation to have multiple subtypes. (The cost of working around this is substantial; Compact strings delivered significant footprint and performance improvements by giving special treatment to strings consisting exclusively of Latin-1 characters, but it would have been far easier and cheaper to do this if String were a sealed class instead of a final one.)
He also mentions that making a final
class sealed
is backward-compatible:
It is a binary- and source-compatible change to make an existing final class sealed. It is neither binary- nor source-compatible to seal a non-final class for which you do not already control all the implementations.
Is there any intention to go back to some of these final
classes in the Java platform and make them sealed
instead to gain performance benefits (i.e., making String
sealed
instead of final
, with a few performant implementations)?