ex08 - Task 2.4 equals ambiguity

Beiträge: 297
Registriert: 1. Okt 2008 19:24

ex08 - Task 2.4 equals ambiguity

Beitrag von olg »

In the task 2.4, I see an ambiguity in the definition of equals. It's definition is as follows
Two stores are equal if both contain the same elements; the order of the elements in the Store is irrelevant. You can use contains and foreach for this implemen- tation.
However, this does not differentiate between the following three scenarios:
A -> (1,1,2)
B -> (1,2,1)
C -> (1,2,2)

Should our implementation of equals hold true for \(A = B = C\) ? Or does 'contains the same elements' only refer to permutations of the same list, i.e., \(A = B\) , but \(A \neq C\) ?
"To Perl, or not to Perl, that is the kvetching." ~Larry Wall

Beiträge: 146
Registriert: 6. Mai 2013 18:04

Re: ex08 - Task 2.4 equals ambiguity

Beitrag von svenamann »

I'm aware of this definition of equals does not take multiplicities into account. Still, it is a valid notion of equality, even though it does not seem to comply to your intuition ;) I chose this on purpose, because it allows you to easily reuse foreach and contains for your implementation.

Remark: Note that this is a general problem with equals! As long as we implement it via the equals and hashCode methods we can only every have one definition of equality for a class, even though we might want to have varying notions depending on the situation.


Zurück zu „Archiv“