Java Closures 2

Compiling Anonymous Classes

Compiling Closures

Mutating Local Variables

Mutating Local Variables 2

Java Bytecodes

Lab

???

Step 1

  1. Compile Lab7.java. What class files are produced?
  2. Use javap to decompile the first anonymous class file.
    javap Lab7\$1

    (The \ is necessary to escape the $ in bash; omit if you use the DOS shell.)

    What do you get? How does it compare with the second slide? (Note: invokespecial invokes a method that does not use the usual dynamic dispatch on the implicit parameter. This is either a constructor call, a call to super, or a call to a private method.)

  3. Run javap -c Lab7\$1 in order to see the bytecodes of the methods. Describe in plain English what the constructor does.

Step 2

  1. Compile ForEachDemo.java with the BGGA compiler. What class files are produced?
  2. Use javap to decompile the anonymous class file. What do you get? How does it compare with the third slide?
  3. Run javap -c. How does the curious +invoke method get called? (No, I don't know why it is a separate method.)

Step 3

  1. Compile Lab8.java with the BGGA compiler. What class files are produced?
  2. Which class files contain the closures?
  3. Decompile the other anonymous class file. What output do you get?
  4. Decompile with java -c as necessary and explain which strategy BGGA uses to mutate the counter variable.