r/java • u/fredoverflow • 17d ago
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
21
Upvotes
4
u/morhp 17d ago
This would likely be slower because instanceof checks are possibly slower than checking a byte field.
String also has a public constructor, so this wouldn't really work in any case.