Created
January 7, 2013 21:57
-
-
Save rklemme/4478864 to your computer and use it in GitHub Desktop.
How Java fakes closures.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lambda; | |
public class FinalTest { | |
public static Runnable create(final int limit) { | |
return new Runnable() { | |
@Override | |
public void run() { | |
for (int i = 0; i < limit; ++i) { | |
System.out.println(i); | |
} | |
} | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Classfile /C:/Users/Robert/workspace/c.l.j.p/bin/classes/lambda/FinalTest.class | |
Last modified 07.01.2013; size 450 bytes | |
MD5 checksum b368e288e05b1d73bb6568fecffe6629 | |
Compiled from "FinalTest.java" | |
public class lambda.FinalTest | |
SourceFile: "FinalTest.java" | |
InnerClasses: | |
#16; //class lambda/FinalTest$1 | |
minor version: 0 | |
major version: 50 | |
flags: ACC_PUBLIC, ACC_SUPER | |
Constant pool: | |
#1 = Class #2 // lambda/FinalTest | |
#2 = Utf8 lambda/FinalTest | |
#3 = Class #4 // java/lang/Object | |
#4 = Utf8 java/lang/Object | |
#5 = Utf8 <init> | |
#6 = Utf8 ()V | |
#7 = Utf8 Code | |
#8 = Methodref #3.#9 // java/lang/Object."<init>":()V | |
#9 = NameAndType #5:#6 // "<init>":()V | |
#10 = Utf8 LineNumberTable | |
#11 = Utf8 LocalVariableTable | |
#12 = Utf8 this | |
#13 = Utf8 Llambda/FinalTest; | |
#14 = Utf8 create | |
#15 = Utf8 (I)Ljava/lang/Runnable; | |
#16 = Class #17 // lambda/FinalTest$1 | |
#17 = Utf8 lambda/FinalTest$1 | |
#18 = Methodref #16.#19 // lambda/FinalTest$1."<init>":(I)V | |
#19 = NameAndType #5:#20 // "<init>":(I)V | |
#20 = Utf8 (I)V | |
#21 = Utf8 limit | |
#22 = Utf8 I | |
#23 = Utf8 SourceFile | |
#24 = Utf8 FinalTest.java | |
#25 = Utf8 InnerClasses | |
{ | |
public lambda.FinalTest(); | |
Signature: ()V | |
flags: ACC_PUBLIC | |
LineNumberTable: | |
line 3: 0 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 5 0 this Llambda/FinalTest; | |
Code: | |
stack=1, locals=1, args_size=1 | |
0: aload_0 | |
1: invokespecial #8 // Method java/lang/Object."<init>":()V | |
4: return | |
LineNumberTable: | |
line 3: 0 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 5 0 this Llambda/FinalTest; | |
public static java.lang.Runnable create(int); | |
Signature: (I)Ljava/lang/Runnable; | |
flags: ACC_PUBLIC, ACC_STATIC | |
LineNumberTable: | |
line 6: 0 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 9 0 limit I | |
Code: | |
stack=3, locals=1, args_size=1 | |
0: new #16 // class lambda/FinalTest$1 | |
3: dup | |
4: iload_0 | |
5: invokespecial #18 // Method lambda/FinalTest$1."<init>":(I)V | |
8: areturn | |
LineNumberTable: | |
line 6: 0 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 9 0 limit I | |
} | |
Classfile /C:/Users/Robert/workspace/c.l.j.p/bin/classes/lambda/FinalTest$1.class | |
Last modified 07.01.2013; size 715 bytes | |
MD5 checksum 86664064f30ce0008e5316c53788f7ab | |
Compiled from "FinalTest.java" | |
class lambda.FinalTest$1 implements java.lang.Runnable | |
SourceFile: "FinalTest.java" | |
EnclosingMethod: #38.#40 // lambda.FinalTest.create | |
InnerClasses: | |
#1; //class lambda/FinalTest$1 | |
minor version: 0 | |
major version: 50 | |
flags: ACC_SUPER | |
Constant pool: | |
#1 = Class #2 // lambda/FinalTest$1 | |
#2 = Utf8 lambda/FinalTest$1 | |
#3 = Class #4 // java/lang/Object | |
#4 = Utf8 java/lang/Object | |
#5 = Class #6 // java/lang/Runnable | |
#6 = Utf8 java/lang/Runnable | |
#7 = Utf8 val$limit | |
#8 = Utf8 I | |
#9 = Utf8 <init> | |
#10 = Utf8 (I)V | |
#11 = Utf8 Code | |
#12 = Fieldref #1.#13 // lambda/FinalTest$1.val$limit:I | |
#13 = NameAndType #7:#8 // val$limit:I | |
#14 = Methodref #3.#15 // java/lang/Object."<init>":()V | |
#15 = NameAndType #9:#16 // "<init>":()V | |
#16 = Utf8 ()V | |
#17 = Utf8 LineNumberTable | |
#18 = Utf8 LocalVariableTable | |
#19 = Utf8 this | |
#20 = Utf8 Llambda/FinalTest$1; | |
#21 = Utf8 run | |
#22 = Fieldref #23.#25 // java/lang/System.out:Ljava/io/PrintStream; | |
#23 = Class #24 // java/lang/System | |
#24 = Utf8 java/lang/System | |
#25 = NameAndType #26:#27 // out:Ljava/io/PrintStream; | |
#26 = Utf8 out | |
#27 = Utf8 Ljava/io/PrintStream; | |
#28 = Methodref #29.#31 // java/io/PrintStream.println:(I)V | |
#29 = Class #30 // java/io/PrintStream | |
#30 = Utf8 java/io/PrintStream | |
#31 = NameAndType #32:#10 // println:(I)V | |
#32 = Utf8 println | |
#33 = Utf8 i | |
#34 = Utf8 StackMapTable | |
#35 = Utf8 SourceFile | |
#36 = Utf8 FinalTest.java | |
#37 = Utf8 EnclosingMethod | |
#38 = Class #39 // lambda/FinalTest | |
#39 = Utf8 lambda/FinalTest | |
#40 = NameAndType #41:#42 // create:(I)Ljava/lang/Runnable; | |
#41 = Utf8 create | |
#42 = Utf8 (I)Ljava/lang/Runnable; | |
#43 = Utf8 InnerClasses | |
{ | |
private final int val$limit; | |
Signature: I | |
flags: ACC_PRIVATE, ACC_FINAL, ACC_SYNTHETIC | |
lambda.FinalTest$1(int); | |
Signature: (I)V | |
flags: | |
LineNumberTable: | |
line 1: 0 | |
line 6: 5 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 10 0 this Llambda/FinalTest$1; | |
Code: | |
stack=2, locals=2, args_size=2 | |
0: aload_0 | |
1: iload_1 | |
2: putfield #12 // Field val$limit:I | |
5: aload_0 | |
6: invokespecial #14 // Method java/lang/Object."<init>":()V | |
9: return | |
LineNumberTable: | |
line 1: 0 | |
line 6: 5 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 10 0 this Llambda/FinalTest$1; | |
public void run(); | |
Signature: ()V | |
flags: ACC_PUBLIC | |
LineNumberTable: | |
line 10: 0 | |
line 11: 5 | |
line 10: 12 | |
line 13: 23 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 24 0 this Llambda/FinalTest$1; | |
2 21 1 i I | |
Code: | |
stack=2, locals=2, args_size=1 | |
0: iconst_0 | |
1: istore_1 | |
2: goto 15 | |
5: getstatic #22 // Field java/lang/System.out:Ljava/io/PrintStream; | |
8: iload_1 | |
9: invokevirtual #28 // Method java/io/PrintStream.println:(I)V | |
12: iinc 1, 1 | |
15: iload_1 | |
16: aload_0 | |
17: getfield #12 // Field val$limit:I | |
20: if_icmplt 5 | |
23: return | |
LineNumberTable: | |
line 10: 0 | |
line 11: 5 | |
line 10: 12 | |
line 13: 23 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 24 0 this Llambda/FinalTest$1; | |
2 21 1 i I | |
StackMapTable: number_of_entries = 2 | |
frame_type = 252 /* append */ | |
offset_delta = 5 | |
locals = [ int ] | |
frame_type = 9 /* same */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment