For example, I have two object, which a the class, Person.
Person A:
User_name:n1
Password:1234
Email:n1@email.com
Person B:
User_name:n1
Password:1234
Email:n1@email.com
Because both Person A and Person B have same values, so, I would like to write my own isValueEqual function. first, I want to compare their classes, then, I campare their value one by one to check whether it is equal. I think this way is super time consuming. So, I think is this reliable to make it become a JSON string, and use the md5 to hash them, and compare the hash only. So, is this a better approach for comparing their value? Thanks.
To explain what Jim Garrison explains in this comment in more details, just consider the work necessary to implement equals by comparing the fields, and the work necessary to implement it by generating a hash and comparing the hashes. Let’s take your example, with A and B differing only by the last letter of their email (which is the worst case).
First method:
Second method:
Note that if the persons differ by the first character or the length of their name, the first method stops immediately, whereas the second one must do every step.