generated lambda names - lambda$null$0

Rafkind, Jon jon.rafkind at hp.com
Tue Oct 7 01:19:42 UTC 2014


Tools that work with bytecode will inevitably come across the generated
lambda method names, and I noticed that lambdas nested inside other
lambdas have strange 'null' names in them.

public class x{
    interface T{
        int g();
    }

    public void test(){
        T t1 = () -> {
            T t2 = () -> 2;
            return 1;
        };
    }
}

The bytecode contains these two desugared lambda methods:

.method synthetic static private lambda$test$1 : ()I
.method synthetic static private lambda$null$0 : ()I

Where lambda$test$1 is the 't1' lambda, and lambda$null$0 is the 't2'
lambda. It's not the end of the world to have 'null' there, but since an
attempt at putting some useful info there is made maybe something better
than 'null' could be chosen.

Tested on jdk8u20.

BTW, javap cannot dissassemble/show any of the generated lambda code.
Perhaps hiding the generated lambda name from the user is ok, but there
is no way to see the method bodies. I was about to write my own
dissassembler based on the ASM library, but I found this nice github
project that works just fine: https://github.com/Storyyeller/Krakatau


More information about the lambda-dev mailing list