|
This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
equals()
Posted by C. Wortz on 05 Oct 1998, 6:39 AM
> You can make your code more elegant and gain some perfomance > improvements by implementing equals in a following manner: > class A { > /* ... */ > public boolean equals(A a) { > /* ... */ > } Your solution may be more elegant and it may give better performance, but it is harder to read and debug. Six months from now you will have to stop and think what your code does, the original is simple to read and understand. I don't know who is going to look at my code, so I favor the simple and easily understood. > public boolean equals(Object o) { > return o instanceof A? equals((A) o) : false; > } > }
Replies:
|