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
1
u/lengors Sep 12 '25
OP is trolling/rage baiting so this is more for people genuinly interested coming across this.
Even for Strings, Java compares them by reference and not by value/content. It's just that when you assign a literal (string) value to two different variables, they reference the same place in memory.
You can see this with the following piece of code: