On Tue, 17 Jan 2023 10:11:49 GMT, Rémi Forax <fo...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/invoke/MethodHandles.java line 6754: >> >>> 6752: filter(t -> t.parameterCount() > skipSize). >>> 6753: map(MethodType::ptypes). >>> 6754: reduce((p, q) -> p.length >= q.length ? p : >>> q).orElse(EMPTY); >> >> Could avoid the need to introduce `EMPTY` if you make the stream expression >> return the longest list directly: >> >> reduce((p, q) -> { >> var longest = (p.size() >= q.size()) ? p : q; >> return List.of(Arrays.copyOfRange(longest, skipSize, >> longest.size()); // checking isEmpty() is redundant here since we filter on >> `t.parameterCount() > skipSize` >> }).orElse(List.of()); > > Using lambdas inside MethodHandles is quite dangerous given that lambdas are > initialized using method handles. It may work now because > longuestParameterList() is not called when initializing a lambda but it may > make any changes in the implementation of lambdas painfull in the future. Precious little method handle use in lambda bootstrap since JDK 11. Though I agree with the sentiment - having fixed a number of bootstrap issues in the past - `MethodHandles` is a small step up the abstraction ladder and the code in particular already uses a number of method refs and lambdas. ------------- PR: https://git.openjdk.org/jdk/pull/12025