I understand that every time I type the string literal ""
, the same String object is referenced in the string pool.
But why doesn’t the String API include a public static final String Empty = "";
, so I could use references to String.Empty
?
It would save on compile time, at the very least, since the compiler would know to reference the existing String, and not have to check if it had already been created for reuse, right? And personally I think a proliferation of string literals, especially tiny ones, in many cases is a “code smell”.
So was there a Grand Design Reason behind no String.Empty, or did the language creators simply not share my views?