RFR: 8263668: Update java.time to use instanceof pattern variable

Michael Kuhlmann jdk at fiolino.de
Wed Mar 24 12:23:08 UTC 2021



On 3/24/21 12:09 PM, Rémi Forax wrote:
> On Wed, 24 Mar 2021 09:56:16 GMT, Patrick Concannon <pconcannon at openjdk.org> wrote:
> 
>> Hi,
>>
>> Could someone please review my code for updating the code in the `java.time` package to make use of the `instanceof` pattern variable?
>>
>> Kind regards,
>> Patrick
> 
> src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java line 168:
> 
>> 166:     private static final TemporalQuery<ZoneId> QUERY_REGION_ONLY = (temporal) -> {
>> 167:         ZoneId zone = temporal.query(TemporalQueries.zoneId());
>> 168:         return (zone != null && (!(zone instanceof ZoneOffset)) ? zone : null);
> 
> i find this code hard to read
> `return (zone != null && (!(zone instanceof ZoneOffset))) ? zone : null;`
> seems better`

The whole null check is not necessary.

`return zone instanceof ZoneOffset ? null : zone;`

> -------------
> 
> PR: https://git.openjdk.java.net/jdk/pull/3170
> 


More information about the core-libs-dev mailing list