>> I just found out that if you create an array of <int>s and popu-
>> late it with the very same values as you have in another array of
>> <int>s, and then call the <equals()> method on the two arrays, it re-
>> turns <false>, even though the two arrays are identical. Anyone know
>> why this is doing this? What use is the <equals()> method defined for
>> each array if I can't use it to tell whether two arrays are equal?
[...]
> Longer answer: probably because Sun didn't think about this.
To be fair, the semantics of "equality" is somewhat context dependent,
in that in some cases, for two arrays to be "equal", all that needs to be
true is that each of its elements are also "equal". In other cases, for two
arrays to be "equal", all that needs to be true is for its elements to be
identical (as in ==). In yet other cases, other semantics might apply.
This is one reason why I wish there was something like the Comparator
interface for equality, so that you could use a different EqualityChecker
object for different semantics.
It's somewhat "dirty" to use Comparator as an EuqualityChecker, and just
check about whether the compareTo() method returns == 0 or != 0, because
Comparator implies a total ordering over the instances of types, which might
not make sense for the data you're working with.
- Oliver
Adam Maass - 26 Apr 2006 05:37 GMT
> To be fair, the semantics of "equality" is somewhat context dependent,
> in that in some cases, for two arrays to be "equal", all that needs to be
[quoted text clipped - 10 lines]
> because Comparator implies a total ordering over the instances of types,
> which might not make sense for the data you're working with.
Long ago and far away, I did a significant amount of programming in Lisp.
Lisp has at least four different notions of equality:
eq
eql
equal
=
If I remember aright, eq tested that the two operands were bound to the same
object; eql evaluted to t if its operands were eq or if its operands were
lists whose elements were pairwise eq; equal evaluated to t if its operands
were eql or if its operands were lists that were pairwise eql.
Essentially, the longer the funtion name, the deeper the compare.
And = was for use with numeric quantities.
Tony Morris - 26 Apr 2006 22:53 GMT
> This is one reason why I wish there was something like the Comparator
> interface for equality, so that you could use a different EqualityChecker
> object for different semantics.
There is. http://contractualj.com/api/net/tmorris/adt/Equalable.html
What you are eluding to, even if you don't know it, is that the OO paradigm
as we know it, is implicitly in contradiction to a formally stated
requirement specification. Think about it some more.

Signature
Tony Morris
http://tmorris.net/