Code examples
Lets have a look at the bytecode produced for some examples.
We're going to look at the bytecode for four distinct blocks of functionality based on the example we looked at in lambdas vs closures
section.
We'll explore:
- A simple anonymous class.
- An anonymous class closing over some variable (an old style closure).
- A lambda with no arguments.
- A lambda with arguments.
- A lambda closing over some variable (a new style closure).
The example bytecode was generated using the javap
command line tool. Only partial bytecode listings are shown in this section, for full source and bytecode listings, see Appendix A
. Also, fully qualified class names have been shortened to better fit on the page.