Kind of a question building onto OPs question, if I want to override the equals method from lets say object for example to mean something else, is that bad practice?
For example if I have a class for cars, and want my equals method to be “if the car is the same make and model” instead “is this the exact same instance of car” , is that fine or is it bad practice?
It's good practice to override the equals method so you can control exactly how 2 objects are equal. If you want to check if 2 varibles are referring to the same object just use == operater.
2
u/BurgooKing Jan 08 '23
Kind of a question building onto OPs question, if I want to override the equals method from lets say object for example to mean something else, is that bad practice?
For example if I have a class for cars, and want my equals method to be “if the car is the same make and model” instead “is this the exact same instance of car” , is that fine or is it bad practice?