Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 12
    You might want to look at Scala, where == is object equality and eq is reference equality (ofps.oreilly.com/titles/9780596155957/…). Commented Apr 2, 2013 at 11:12
  • Just as a note, and this may not help you, but as far as I remember, you can compare string literals with an '==' Commented Apr 2, 2013 at 16:07
  • 10
    @Kgrover: you can, but that's just a convenient by-product of reference equality and how Java aggressively optimizes string matching literals into references to the same object. In other words, it works, but for the wrong reasons. Commented Apr 2, 2013 at 19:29
  • 1
    @aviv the == operator only maps to Equals if the == operator was implemented that way. The default behavior for == is the same as ReferenceEquals (actually, ReferenceEquals is defined as the object version of ==) Commented Apr 3, 2013 at 11:49
  • 3
    It's a consequence of design decisions which make a lot of sense in many other scenarios. But since you seem to know that and be asking this anyways, I feel compelled to counter your question: Why does there have to be a use case for String reference comparison? Commented Oct 20, 2015 at 15:23