RFR: 8365620: Using enhanced switch in MethodHandleDesc
Chen Liang
liach at openjdk.org
Fri Aug 15 20:08:46 UTC 2025
On Thu, 14 Aug 2025 04:49:28 GMT, Shaojin Wen <swen at openjdk.org> wrote:
> In MethodHandleDesc, the `ofField` method uses enhanced switch, while the `of` and `ofMethod` methods use traditional switch. The same class should have a unified style.
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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26769#discussion_r2278135364
More information about the core-libs-dev
mailing list