On Fri, 15 Aug 2025 06:57:14 GMT, Shaojin Wen <s...@openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/constant/MethodHandleDesc.java line 
>> 123:
>> 
>>> 121:             case VIRTUAL, SPECIAL, INTERFACE_VIRTUAL, 
>>> INTERFACE_SPECIAL, INTERFACE_STATIC, STATIC, CONSTRUCTOR
>>> 122:                     -> new DirectMethodHandleDescImpl(kind, owner, 
>>> name, lookupMethodType);
>>> 123:             default -> throw new 
>>> IllegalArgumentException(kind.toString());
>> 
>> I recommend using `case GETTER, SETTER, STATIC_GETTER, STATIC_SETTER` 
>> explicitly in case we have more kinds in the future, this will become a 
>> compile error and remind us to update. And we can remove the default branch.
>
> If we remove the default case, unexpected behavior may occur when 
> DirectMethodHandleDesc.Kind adds new enum values.

That won’t happen as this is an enhanced switch expression, which must be 
exhaustive at compile time (and gets an implicit `throw new MatchException(…)` 
default clause for exhaustiveness checking at runtime).

Suggestion:

            case GETTER, SETTER, STATIC_GETTER, STATIC_SETTER
                -> throw new IllegalArgumentException(kind.toString());

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26769#discussion_r2278557045

Reply via email to