RFR: 8263358: Update java.lang to use instanceof pattern variable

Brian Goetz brian.goetz at oracle.com
Wed Mar 10 14:17:45 UTC 2021

These patches are obviously minimally correct.  However, for equals 
methods at least, I would take them one step further, from:

             if (!(o instanceof Key that)) return false;
             //noinspection StringEquality (guaranteed interned String(s))
             return name == that.name &&
                    Arrays.equals(ptypes, that.ptypes);


     return (o instanceof Key that)
         && name == that.name
         && Arrays.equals(ptypes, that.ptypes);

The use of "if it's not, return false" is a holdover from when we 
couldn't express this as a single expression (which is almost always 
preferable), which means we had to fall back to control flow.  Now we 
don't have to.

On 3/10/2021 8:04 AM, Patrick Concannon wrote:
> Hi,
> Could someone please review my code for updating the code in the `java.lang` package to make use of the `instanceof` pattern variable?
> Kind regards,
> Patrick
> -------------
> Commit messages:
>   - 8263358: Update java.lang to use instanceof pattern variable
> Changes: https://git.openjdk.java.net/jdk/pull/2913/files
>   Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2913&range=00
>    Issue: https://bugs.openjdk.java.net/browse/JDK-8263358
>    Stats: 62 lines in 18 files changed: 0 ins; 31 del; 31 mod
>    Patch: https://git.openjdk.java.net/jdk/pull/2913.diff
>    Fetch: git fetch https://git.openjdk.java.net/jdk pull/2913/head:pull/2913
> PR: https://git.openjdk.java.net/jdk/pull/2913

More information about the core-libs-dev mailing list