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.

11
  • "I'm not sure, but I think that in Java 7 or 8 oracle made an exception in the compiler to recognize str1 == str2 as str1.equals(str2)": I would not be surprised: Oracle seems to be less concerned with minimalism than Sun was. Commented Apr 2, 2013 at 10:55
  • 2
    If true, that's a very ugly hack since it means there's now one class the language treats differently from all others and breaks code that compares references. :-@ Commented Apr 2, 2013 at 11:02
  • 1
    @WillihamTotland: Consider the opposite case. Currently, if I create two strings, s1 and s2 and give them the same contents, they pass the equality (s1.equals(s2)) comparison but not the same-reference (==) comparison because they're two different objects. Changing the semantics of == to mean equality would cause s1 == s2 to evaluate true where it used to evaluate false. Commented Apr 2, 2013 at 11:30
  • 2
    @Brlfl: While that is true, that sounds like an exceptionally bad thing to rely on in the first place, as strings are immutable, internable objects. Commented Apr 2, 2013 at 11:37
  • 2
    @Giorgio: "Java 7 or 8 oracle made an exception in the compiler to recognize str1 == str2 as str1.equals(str2)" Nope, the Java Language Specification says: Reference Equality Operators: "If the operands of an equality operator are both of either reference type or the null type, then the operation is object equality." That's all folks. I didn't find anything new about this in the Java 8 early draft either. Commented Jan 21, 2014 at 23:47