I'd like to get confirmation that I understand the following exactly.
Is that what I understand?
java
In general, the answer to the above question is "Yes". However...
The equals() method compares only those written for comparison. It's nothing more, nothing less.
If you do not override the equals() method in the class, the equals(Objecto)
method of the nearest superclass that overrides this method is the default.
If you do not have superflats that override the equals() method, the method Object#equals(Objecto)
defined by the object class, which is the top superclass, is the default. It shows the same result as the ==
operator. That is, returns true only for two variables that refer to the same object. So you want to test the identity of the object and the non-functional identity.
Always remember that to override the equals()
method, you must also override the hashCode()
. If the equals()
method has the same value for both objects, the result returned from hashCode()
for both objects must be the same. The opposite is not necessarily true.
© 2024 OneMinuteCode. All rights reserved.