Is Java's assertEquals method reliable?

前端 未结 7 1691
[愿得一人]
[愿得一人] 2020-11-29 18:05

I know that == has some issues when comparing two Strings. It seems that String.equals() is a better approach. Well, I\'m doing JUni

相关标签:
7条回答
  • 2020-11-29 18:44

    In a nutshell - you can have two String objects that contain the same characters but are different objects (in different memory locations). The == operator checks to see that two references are pointing to the same object (memory location), but the equals() method checks if the characters are the same.

    Usually you are interested in checking if two Strings contain the same characters, not whether they point to the same memory location.

    0 讨论(0)
提交回复
热议问题