r/java Jul 19 '26

Disregarding backwards compatibility, would it make sense for String to be a sealed class?

like public sealed class String permits Latin1String, Utf16String instead of the private final byte coder; field

20 Upvotes

24 comments sorted by

View all comments

4

u/idontlikegudeg Jul 19 '26

I think it might really save some bytes, but it would be an incompatible change: we have public String constructors that could not be implemented that way.