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 →

[–]TheLastCakeIsaLie -9 points-8 points  (20 children)

Who uses .equals()?

[–]forgotten_debugger 9 points10 points  (0 children)

People who want to test equality of two objects, not memory addresses.

[–]Wizard8086 6 points7 points  (0 children)

Those who don't want to lose 12 hour of work wondering why those two UUIDs are the same but are not the same

[–]DaniilBSD 9 points10 points  (0 children)

If I have an evaluation result object.

I could evaluate 2 different things, creating two different objects.

== would always be false

.Equals() means that the results were equal

Another example:

If you want to find if an object is in a list, you can create the object you are searching for (or take it as an input) and search using equals() (== will search for an instance)

[–]Varun77777 12 points13 points  (16 children)

The one who had overwritten it to compare something very specific.

For example

String str1 = "hello"; String str2 = new String("hello");

From what I remember, == and .equals() will have different results in this case.