RFR: 8311162: Simplify and modernize equals and hashCode for java.net

Mark Sheppard msheppar at openjdk.org
Fri Jun 30 15:09:53 UTC 2023


On Fri, 30 Jun 2023 09:17:42 GMT, Pavel Rappo <prappo at openjdk.org> wrote:

> Please review this PR to use modern APIs and language features to simplify `equals` and `hashCode` for the java.net package.
> 
> Note, in NetworkInterface we could do even more and change this:
> 
>         for (InetAddress thisAddr : this.addrs) {
>             boolean found = false;
>             for (InetAddress thatAddr : that.addrs) {
>                 if (thisAddr.equals(thatAddr)) {
>                     found = true;
>                     break;
>                 }
>             }
>             if (!found) {
>                 return false;
>             }
>         }
>         return true;
> 
> to this:
> 
>         return Set.of(that.addrs).containsAll(Set.of(this.addrs));
> 
> But arguably, the first option is already better enough than what was there before.

right so, well that aside, one could consider the overhead in instantiating the Sets !!
What also stands out wrt NetworkInterface::equals is a perceived anomaly that when available the MAC address is not considered part of the "equation"

-------------

PR Comment: https://git.openjdk.org/jdk/pull/14726#issuecomment-1614792282


More information about the net-dev mailing list