P
pek
Recently I've been thinking about the equals method a lot. I am
reading Effective Java and there is an item that talks about the
equals method. Several questions came to my mind, like Why compare a
class with it's superlcass? (http://groups.google.com/group/
comp.lang.java.programmer/browse_thread/thread/01c79dc569d1a480) and
others.
Another question I have is:
Why use Object as a parameter in the equals method?
Why don't just narrow it down as much as possible? If I have a Point
class, why not use public boolean equals(Point p); ? Not only will
this make the method easier to create, it will avoid comparing
superclasses (but not subclasses). After all, for most of the cases, I
will compare an object with another object of the same class anyway.
Of course, if you intend to compare with objects of different classes,
this would be irrelevant. But, how many times do you do that anyway?
Thank you,
Panagiotis
reading Effective Java and there is an item that talks about the
equals method. Several questions came to my mind, like Why compare a
class with it's superlcass? (http://groups.google.com/group/
comp.lang.java.programmer/browse_thread/thread/01c79dc569d1a480) and
others.
Another question I have is:
Why use Object as a parameter in the equals method?
Why don't just narrow it down as much as possible? If I have a Point
class, why not use public boolean equals(Point p); ? Not only will
this make the method easier to create, it will avoid comparing
superclasses (but not subclasses). After all, for most of the cases, I
will compare an object with another object of the same class anyway.
Of course, if you intend to compare with objects of different classes,
this would be irrelevant. But, how many times do you do that anyway?
Thank you,
Panagiotis