Skip to main content
1 of 5
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.

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