On Wed, 10 Mar 2021 15:08:53 GMT, Claes Redestad <redes...@openjdk.org> 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 > > Great. I included some of these in #2300 - @mlchung has asked me to split out > some of the changes in that PR to make them more focused and easier to > review, so I'll just go ahead and remove the things you're patching up here. > _Mailing list message from [Brian Goetz](mailto:brian.go...@oracle.com) on > [hotspot-compiler-dev](mailto:hotspot-compiler-...@openjdk.java.net):_ > > 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); > > to > > ??? 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: Thanks for the suggestion, Brian. I've done this now and it can be viewed in commit e9d9131 ------------- PR: https://git.openjdk.java.net/jdk/pull/2913