Hi,
As I see the "problem".
Pair.equal() returns true if the other entity is not an instance of Pair.
In this case it is a Map.Entry.
Map.Entry.equals() howewer checks if the other is an instance of the same
class. So if we want them to be equals, we should change the Map.Entry,
that is out of our limit of power. To make it symmetric we could check for
the instances of the same class also (and return false in this case), but I
think we don't want this.

Dávid

Alex Tsvetkov <a.e.tsvet...@gmail.com> ezt írta (időpont: 2024. szept. 26.,
Cs 13:11):

> Hi.
>
> I found a bug in the implementation of the method `equals` of class `Pair`.
>
> Implementation must be symmetric. Current implementation is not.
>
> Her test showing the problem:
>
> ```
>
> @Test
> void run() {
>     var pair = Pair.of("a", "b");
>     var entry = new Map.Entry<String, String>() {
>         public String getKey() { return "a"; }
>         public String getValue() { return "b"; }
>         public String setValue(String value) { return null; }
>     };
>     assertTrue(pair.equals(entry)); // true
>     assertTrue(entry.equals(pair)); // false
> }
> ```
>

Reply via email to