So we use Object here instead of the class type we're overriding this equals method for? Is this so that we can use it to check different types? (overloading?)
How exactly do we check the values stored in each object though?
All things are lawful, but not all things are profitable.
Knute Snortum wrote:
So we use Object here instead of the class type we're overriding this equals method for? Is this so that we can use it to check different types? (overloading?)
If you don't use Object as the parameter type, you're overloading, not overriding.
Knute Snortum wrote:First check whether the parameter is the same class, then cast the object to the class, then test each of its fields. I can be more specific if necessary.
All things are lawful, but not all things are profitable.
There are three exceptions to that rule:-Knute Snortum wrote: . . .
Yes, you have to be careful with ==. Use it only with primitives. . . .
Campbell Ritchie wrote:You do realise that the equals method is one of the most complicated things in Java programming?
All things are lawful, but not all things are profitable.
Danny Treart wrote:Isn't "==" only used to compare and see if two things are referencing the same object (when not dealing with primatives)?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
You don't mean eliminate but confirm.Winston Gutkowski wrote: . . . It's simply a quick check to eliminate ONE possibility. . . .
HIH
Winston
Rico Felix wrote:All elements that we model on a computer system is just an abstraction to the underlying bit patterns
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are three kinds of actuaries: those who can count, and those who can't.
The commonest problem is that you put Object obj into a Collection and cannot get it back. That might not bring down planes out of the air or cause reactors to melt their way down into the soil, but it might cause failure of your website to sell the pink skirt which appeared a minute ago. If that sort of thing becomes well‑known it might cost your employer millions in lost sales. It could result in thousands of complaints about wrong amounts in bank accounts or wrong amounts of tax taken.Piet Souris wrote: . . . or is it in practise a big problem? . . .
Greetz,
Piet
Campbell Ritchie wrote:If that sort of thing becomes well‑known it might cost your employer millions in lost sales...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Consider Paul's rocket mass heater. |