Skip to main content
2 of 5
added 288 characters in body
Joonas Pulakka
  • 23.6k
  • 9
  • 67
  • 93

I guess it's just consistency, or "principle of least astonishment". String is an object, so it would be surprising if was treated differently than other objects on the runtime level.

At the time when Java came out (~1995), merely having something like String was total luxury to most programmers who were accustomed to representing strings as null-terminated arrays. Subtly changing the behavior later on could have surprising, undesired effects in working programs.

As a side note, you could use String.intern() to get a canonical (interned) representation of the string, after which comparisons could be made with ==. Interning takes some time, but after that, comparisons will be really fast.

Joonas Pulakka
  • 23.6k
  • 9
  • 67
  • 93