Comment by pjmlp

2 days ago

I had another idea given Brian's talk on the matter.

Never bothered to actually look into the generated bytecodes.

Surprisingly hard to find good docs on this. [1]

I was wrong, it looks like the case I gave is one which doesn't result in a new anonymous class being generated. Instead the lambda metafactory gets involved to avoid that allocation.

I apparently didn't see what I thought I saw. I thought that I had seen new `lambda.$1` classes being created in call stacks when debugging. Maybe I did, but the lambda was serializable (we have that in some unfortunate places in our code base).

There are still cases where new classes get generated, but that's pretty much just for serialization.

[1] https://cr.openjdk.org/~briangoetz/lambda/lambda-translation...