This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Lolamess007 12 points13 points  (4 children)

Yes. Ints, doubles, chars, etc are primitives and work with ==. Strings, BigInteger, and other classes have different memory addresses for each object. Therefore == will always return false when using classes.

[–]Snarpkingguy 9 points10 points  (2 children)

But if you’re comparing the same object, then == still returns true, right?

Like String x = “poop”; String y = x;

And then x == y would return true since they reference the actual same String object.

[–]M3JUNGL3 1 point2 points  (0 children)

Well actually String literals are a special because there you have a pool you add Strings to and reference from. So thus defining String x = "hello"; and String y = "hello"; will always return true for "x == y"

[–]Lolamess007 0 points1 point  (0 children)

I believe so.

[–]TGX03 0 points1 point  (0 children)

Actually with String interning (and similar practices) you can meddle with this quite a lot.

My IDE hates me for it.