Is lamb being collected?

If I'm not mistaken, in certain situations lambda in Java is generated as an instance of an anonymous class. For example, in this lambda code, you need to capture a variable from the outside:

final int local = 123456;
list.forEach(x -> System.out.println(x + local));

Does this mean that the garbage collector will require lambda as an object?

+4
source share
2 answers

No, it will not; this is not how lambdas work.

Yes, an instance of the class is generated; no, he will not disappear.

- , invokedynamic; , , JIT , , . , " " .

- , , JIT {static, virtual, interface, special} , . , JIT, .

+6

, , -, , , . , , , , -, .

, , -. factory invokedynamic call. factory , . factory , , .

, - , bootstrap , . , .

, invokedynamic -, : http://mydailyjava.blogspot.no/2015/03/dismantling-invokedynamic.html?m=1

HotSpot, .

+8

All Articles