-5
Objects are types by reference, so the basic values of objects are pointers that indicate where the value of the object really is, is a form of indirect.
When comparing the values of the variables, the comparison is made between pointers. If you have two different objects it is certain that they are at different memory addresses, then obviously the pointers contained in these variables are different, so it is false.
The contents of the objects may be equal, but this is a coincidence, the objects are different, no comparison is made with the contents of the object itself.
Exceptions may exist, for example the type String
which is a reference, but has semantics of type by value, so the comparison happens to be made over the content of the object and not its reference, but it was explicitly defined that it would be made like this, it is not the normal.
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero