Loop.times(5, () -> {
System.out.println("looping");
});
Which of these would it effectively compile to?
for(int i = 0; i < 5; i++)
System.out.println("looping");
or something like
new CallableInterfaceImpl(){
public void call(){
for(int i = 0; i < 5; i++)
System.out.println("looping");
}
}.call();
So would it replace (kind of inline), or actually create an anonymous class?
The VM decides how to implement lambda, not a compiler.
See
Translation strategy
section in Translation of Lambda Expressions.for
construction from your example is most effective way in terms of simple compiling or perfomance (but the performance differences are very small, by the tests).Addon:
I created and disassemble two examples:
Disassembled bytecode, constants and other information:
and
Disassembled bytecode, constants and other information:
Compiler generated class-file is more complicated and larger (771b vs 1262b) for Lambda example.