since method references can be as debug-friendly as lambda expressions, perhaps they should be?

Remi Forax forax at univ-mlv.fr
Mon Aug 16 21:22:34 UTC 2021


----- Original Message -----
> From: "mark yagnatinsky" <mark.yagnatinsky at barclays.com>
> To: "jdk-dev" <jdk-dev at openjdk.java.net>
> Sent: Lundi 16 Août 2021 20:22:17
> Subject: since method references can be as debug-friendly as lambda expressions, perhaps they should be?

> I recently saw a cool blog post by Tagir Valeev about how to make method
> references as debug-friendly as lambda expressions:
> https://habr.com/en/post/569414/
> If something like this were adopted, then Java developers could choose lambda
> expressions vs method references purely based on what makes the code easier to
> read, instead of having to make annoying trade-offs such as "a method reference
> is more readable in this case, but a lambda expression will give me better
> stack traces if something goes wrong".
> 
> Thoughts?

It's a fun hack, and i don't think anyone want such horror in the real implementation.

There is also an issue if in the future we want to use a ldc constant dynamic instead of invokedynamic in the generated code because in that case,
the lambda proxy will be shared in between two method references
  Consumer<Object> c1 = Objects::requireNonNull;
  Consumer<Object> c2 = Objects::requireNonNull;

regards,
Rémi


More information about the jdk-dev mailing list