+ 2
Equal method help
are the steps for equal method always in this manner?check reference,then null, class,then class object...is it fixed?why most of the examples i found in the internet use similar steps https://code.sololearn.com/c4N53fpRFu70/?ref=app
6 Answers
+ 3
The order of reference or null check doesn't matter.
Although, you do need to do the null check before the class check, and you need to do a class check before a downcast. This is just to avoid errors.
+ 2
Ya but you can simplify by just calling the super!
+ 2
Because its the equals of two object but you can avoid those things!
+ 2
We are giving our own interpretation of equality, that is what the steps are for.
If the two objects are equal with ==, then we know the equality of them is the same. If the Object is null, we know it is definitely not equal. Plus if we tried to downcast a null Object, we would get an exception.
etc..
+ 1
i thought the use of overriding equal method is to give our own interpretation of equality?why does it still has to follow the series of steps?
+ 1
thankyou so much u are so helpful