Skip to main content

System.equals(a,b)

2 replies [Last post]
regexguy
Offline
Joined: 2003-06-20
Points: 0

After all the discussions about equals here, I can't remember if this suggestion percolated to the top...

I think there should be a System.equals() that is a symmetric operation. (Rather than everyone coding a utility class to do this) It should know about subclasses, and call the subclass' equals(), or if there is no super/sub class relationship it should return a.equals(b) && b.equals(a).

I think it should also know about primitive types. There is that weirdness in java that

2 == 2. is true

but

new Integer(2).equals(new Double(2)) is false.

I think System.equals(2,2.) should overload the primitive types and return true in this case.

IMHO, I think that the fact that the primitive and object versions are different is a bug now that we have autoboxing.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joergwassmer
Offline
Joined: 2004-09-20
Points: 0

Before the operater overloading for the Java primitive wrappers I have never seen such a silly stuff in the Java language.

Instead to implement workarounds the whole thing should be revoked before too many people are using it. At least there should be a compiler option that causes a warning and optionally an error.

Generally the "equals problem" is some kind of fake, I think. You always have a context which defines what equality means. If an object's equals method is not sufficient you have to compare using your own method. Checking for equality of classes inside the equals method does not help you out if you have the need for multiple definitions of equality on the same object.

For the primitive wrappers the solution is quite simple - use equals() to take classes into account, use values to ignore them.

kcpeppe
Offline
Joined: 2003-06-15
Points: 0

I'd say it was a bug before we had autoboxing.