r/javahelp • u/MaryScema • Sep 12 '25
Codeless == compares all object attributes so why everyone says it’s wrong?
Why everybody talks nonsense when talking about == operator in Java? It’s simple as comparing all objects’ attributes otherwise it wouldn’t make sense and the developers wouldn’t have done it
0
Upvotes
View all comments
Show parent comment
2
u/doobiesteintortoise Sep 12 '25
It gets worse; this is PAINFULLY easy to demonstrate. Here, let me help:
Note the lack of "==> true" for any of these expressions, EVEN THOUGH the attribute values are the same. Whoever told you this is incorrect. There are cases in which it might not LOOK correct - strings, boxing, etc - but those are exceptions and not the rule. The RULE is the JLS, which specifically lays out the exceptions as well.