RFR: 8300543 Compiler Implementation for Pattern Matching for switch [v2]

Jan Lahoda jlahoda at openjdk.org
Thu Apr 20 13:35:56 UTC 2023


On Wed, 19 Apr 2023 04:06:00 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> Jan Lahoda has updated the pull request incrementally with six additional commits since the last revision:
>> 
>>  - Fixing infinite loop where a binding pattern is replaced with a binding pattern for the same type.
>>  - Reflecting review comments.
>>  - Fixing exhaustiveness for unsealed supertype pattern.
>>  - No need to enable features after error reported.
>>  - SwitchBootstraps.typeSwitch should not initialize enum classes.
>>  - A prototype of avoiding enum initialization.
>
> src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 170:
> 
>> 168:             } else if (label instanceof EnumDesc<?> enumDesc) {
>> 169:                 if (target.getClass().isEnum() &&
>> 170:                     ((Enum<?>) target).describeConstable().stream().anyMatch(d -> d.equals(enumDesc))) {
> 
> probably a matter of style but isn't it a bit too much to use streams here? there will be always only one element right?

Technically, one element, but the type is optional, so formally could be no elements. I could use `.get()`, but that feels a bit ugly and against optional?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13074#discussion_r1172599496


More information about the core-libs-dev mailing list