+ 3

a == b, a is b

why the answers of "obj1 == obj2" & " obj1 is obj2" are different? (somtimes)

10th Jun 2017, 8:02 AM
•| Parsa_kzr |•
•| Parsa_kzr |• - avatar
1 Respuesta
+ 5
Object has reference not values so comparison will be based on object reference. The equality operator "==" will works well with primitive values not for reference values. For object comparison u need to overload equals() and hasCode() methods in the class. So in ur case obj1 and obj2 may have different references i.e. their hasCode values will be different.
10th Jun 2017, 8:19 AM
Sbk0103
Sbk0103 - avatar