you are viewing a single comment's thread
view the rest of the comments
[–] 10 points 9 months ago (4 children)

Is there ever an instance when you do want to compare object identity instead of “equal”-ness? I find this behaviour just confusing for beginners and not useful for experts.

  • source
  • hideshow 8 child comments
  • [–] 5 points 9 months ago (1 child)

    There are use cases. Like containers where the pointer to the object itself is the key (for example a set). But they are niche and should be implemented by the standard library anyway. One of the things I hate most about Java is .equals() on strings. 99.999% of times you compare strings, you want to compare the contents, yet there is a reserved operator to do the wrong comparison.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 1 point 9 months ago

    Is there ever an instance when you do want to compare object identity instead of “equal”-ness?

    Maybe if you have to check if the object is one you already hold a lock for or account for some similar consequence of questionable architecture.

  • source
  • parent