RFR: 8311162: Simplify and modernize equals and hashCode for java.net
Pavel Rappo
prappo at openjdk.org
Fri Jun 30 10:54:52 UTC 2023
On Fri, 30 Jun 2023 09:34:26 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:
> > `return Set.of(that.addrs).containsAll(Set.of(this.addrs));`
>
> Since it's been checked before that the arrays have the same length it could even be:
>
> ```
> return Set.of(that.addrs).equals(Set.of(this.addrs));
> ```
While this would be clearer and likely as intended, it wouldn't be equivalent. It would only be equivalent, if we could guarantee that there are no duplicates in `this.addrs`.
On the other hand, if there are duplicates in `this.addrs` then there should also be the same duplicates in `that.addrs`, or else `equals` will not be symmetric, which it is required to be, and hence will be a bug:
this.addrs.equals(that.addrs) != that.addrs.equals(this.addrs)
So with that it mind, do you want me to change to what you proposed and see if the tests are still okay?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14726#issuecomment-1614482760
More information about the net-dev
mailing list