> 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.
- Re: RFR: 8258422: Cleanup unnecessary null comparison... Stuart Marks
- Re: RFR: 8258422: Cleanup unnecessary null compar... Chris Hegarty
- Re: RFR: 8258422: Cleanup unnecessary null co... Andrey Turbanov
- Re: RFR: 8258422: Cleanup unnecessary nul... Aleksei Efimov
- Re: RFR: 8258422: Cleanup unnecessary null comparison befo... Andrey Turbanov
- Re: RFR: 8258422: Cleanup unnecessary null comparison befo... Andrey Turbanov
- Re: RFR: 8258422: Cleanup unnecessary null comparison... Chris Hegarty
- Re: RFR: 8258422: Cleanup unnecessary null compar... Aleksei Efimov
- Re: RFR: 8258422: Cleanup unnecessary null co... Andrey Turbanov
- Re: RFR: 8258422: Cleanup unnecessary null compar... Paul Sandoz
- Re: RFR: 8258422: Cleanup unnecessary null comparison befo... Andrey Turbanov
- Re: RFR: 8258422: Cleanup unnecessary null comparison... Chris Hegarty
- Re: RFR: 8258422: Cleanup unnecessary null comparison... Alan Bateman
- Re: RFR: 8258422: Cleanup unnecessary null compar... Andrey Turbanov
- Re: RFR: 8258422: Cleanup unnecessary null co... Daniel Fuchs
- Re: RFR: 8258422: Cleanup unnecessary nul... Alan Bateman
- Re: RFR: 8258422: Cleanup unnecessary null comparison... Aleksei Efimov
- Re: RFR: 8258422: Cleanup unnecessary null compar... Chris Hegarty
- Re: RFR: 8258422: Cleanup unnecessary null co... Aleksei Efimov
- Re: RFR: 8258422: Cleanup unnecessary nul... Chris Hegarty