> On Dec 16, 2020, at 1:47 AM, Chris Hegarty <che...@openjdk.java.net> wrote:
> 
> On Wed, 16 Dec 2020 09:20:09 GMT, Andrey Turbanov 
> <github.com+741251+turban...@openjdk.org> wrote:
> 
>>> 8258422: Cleanup unnecessary null comparison before instanceof check in 
>>> java.base
>> 
>> Andrey Turbanov has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>  8258422: Cleanup unnecessary null comparison before instanceof check in 
>> java.base
>>  use instanceof pattern matching in UnixPath too
> 
> Let's take advantage of "flow scoping" to eliminate some of these casts. A 
> few examples follow.
> 
> src/java.base/share/classes/java/net/InetSocketAddress.java line 414:
> 
>> 412:         if (!(obj instanceof InetSocketAddress))
>> 413:             return false;
>> 414:         return holder.equals(((InetSocketAddress) obj).holder);
> 
> If we restructure this a little we can get:
> 
>    public final boolean equals(Object obj) {
>        if (obj instanceof InetSocketAddress that)
>            return holder.equals(that.holder);
>        return false;
>    }
> 

It’s also possible to use a ternary expression as in:

   return (obj instanceof InetSocketAddress that) ? holder.equals(that.holder) 
: false;

Not suggesting you have to do that here. More for information purposes for 
those that might not know.

Paul.

Reply via email to