RFR: 8263233: Update java.net and java.nio to use instanceof pattern variable

Chris Hegarty chegar at openjdk.java.net
Tue Mar 9 12:37:08 UTC 2021


On Tue, 9 Mar 2021 11:07:07 GMT, Patrick Concannon <pconcannon at openjdk.org> wrote:

> Hi,
> 
> Could someone please review my code for updating the code in the `java.net` and `java.nio` packages to make use of the `instanceof` pattern variable?
> 
> Kind regards,
> Patrick

src/java.base/share/classes/java/net/InterfaceAddress.java line 107:

> 105: 
> 106:             if (Objects.equals(address, cmp.address) &&
> 107:                 Objects.equals(broadcast, cmp.broadcast) &&

This could be simplified to:

    public boolean equals(Object obj) {
        if (obj instanceof InterfaceAddress cmp
              && Objects.equals(address, cmp.address)
              && Objects.equals(broadcast, cmp.broadcast)
              && maskLength == cmp.maskLength) {
            return true;
        }
        return false;
    }

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

PR: https://git.openjdk.java.net/jdk/pull/2890


More information about the net-dev mailing list