Java8 Lambda and its disassembled bytecode by javap
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 /***/Foo.class | |
Last modified 2014/01/22; size 1603 bytes | |
MD5 checksum 79b51e1db200ecc888a111f97c169832 | |
Compiled from "Foo.java" | |
class Foo | |
SourceFile: "Foo.java" | |
InnerClasses: | |
public static final #78= #77 of #81; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles | |
BootstrapMethods: | |
0: #29 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; | |
Method arguments: | |
#30 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
#31 invokestatic Foo.f1:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#32 (Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
1: #29 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; | |
Method arguments: | |
#30 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
#35 invokespecial Foo.f2:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#32 (Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
2: #29 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; | |
Method arguments: | |
#30 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
#37 invokestatic Foo.lambda$main$0:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#32 (Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
minor version: 0 | |
major version: 52 | |
flags: ACC_SUPER | |
Constant pool: | |
#1 = Methodref #13.#26 // java/lang/Object."<init>":()V | |
#2 = Class #27 // Foo | |
#3 = Methodref #2.#26 // Foo."<init>":()V | |
#4 = InvokeDynamic #0:#33 // #0:apply:()Ljava/util/function/BiFunction; | |
#5 = Methodref #13.#34 // java/lang/Object.getClass:()Ljava/lang/Class; | |
#6 = InvokeDynamic #1:#36 // #1:apply:(LFoo;)Ljava/util/function/BiFunction; | |
#7 = InvokeDynamic #2:#33 // #2:apply:()Ljava/util/function/BiFunction; | |
#8 = Fieldref #38.#39 // java/lang/System.out:Ljava/io/PrintStream; | |
#9 = Methodref #40.#41 // java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
#10 = InterfaceMethodref #42.#43 // java/util/function/BiFunction.apply:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
#11 = Methodref #44.#45 // java/io/PrintStream.println:(Ljava/lang/Object;)V | |
#12 = Methodref #40.#46 // java/lang/Integer.intValue:()I | |
#13 = Class #47 // java/lang/Object | |
#14 = Utf8 <init> | |
#15 = Utf8 ()V | |
#16 = Utf8 Code | |
#17 = Utf8 LineNumberTable | |
#18 = Utf8 main | |
#19 = Utf8 ([Ljava/lang/String;)V | |
#20 = Utf8 f1 | |
#21 = Utf8 (Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#22 = Utf8 f2 | |
#23 = Utf8 lambda$main$0 | |
#24 = Utf8 SourceFile | |
#25 = Utf8 Foo.java | |
#26 = NameAndType #14:#15 // "<init>":()V | |
#27 = Utf8 Foo | |
#28 = Utf8 BootstrapMethods | |
#29 = MethodHandle #6:#48 // invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; | |
#30 = MethodType #49 // (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
#31 = MethodHandle #6:#50 // invokestatic Foo.f1:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#32 = MethodType #21 // (Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#33 = NameAndType #51:#52 // apply:()Ljava/util/function/BiFunction; | |
#34 = NameAndType #53:#54 // getClass:()Ljava/lang/Class; | |
#35 = MethodHandle #7:#55 // invokespecial Foo.f2:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#36 = NameAndType #51:#56 // apply:(LFoo;)Ljava/util/function/BiFunction; | |
#37 = MethodHandle #6:#57 // invokestatic Foo.lambda$main$0:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#38 = Class #58 // java/lang/System | |
#39 = NameAndType #59:#60 // out:Ljava/io/PrintStream; | |
#40 = Class #61 // java/lang/Integer | |
#41 = NameAndType #62:#63 // valueOf:(I)Ljava/lang/Integer; | |
#42 = Class #64 // java/util/function/BiFunction | |
#43 = NameAndType #51:#49 // apply:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
#44 = Class #65 // java/io/PrintStream | |
#45 = NameAndType #66:#67 // println:(Ljava/lang/Object;)V | |
#46 = NameAndType #68:#69 // intValue:()I | |
#47 = Utf8 java/lang/Object | |
#48 = Methodref #70.#71 // java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; | |
#49 = Utf8 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
#50 = Methodref #2.#72 // Foo.f1:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#51 = Utf8 apply | |
#52 = Utf8 ()Ljava/util/function/BiFunction; | |
#53 = Utf8 getClass | |
#54 = Utf8 ()Ljava/lang/Class; | |
#55 = Methodref #2.#73 // Foo.f2:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#56 = Utf8 (LFoo;)Ljava/util/function/BiFunction; | |
#57 = Methodref #2.#74 // Foo.lambda$main$0:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#58 = Utf8 java/lang/System | |
#59 = Utf8 out | |
#60 = Utf8 Ljava/io/PrintStream; | |
#61 = Utf8 java/lang/Integer | |
#62 = Utf8 valueOf | |
#63 = Utf8 (I)Ljava/lang/Integer; | |
#64 = Utf8 java/util/function/BiFunction | |
#65 = Utf8 java/io/PrintStream | |
#66 = Utf8 println | |
#67 = Utf8 (Ljava/lang/Object;)V | |
#68 = Utf8 intValue | |
#69 = Utf8 ()I | |
#70 = Class #75 // java/lang/invoke/LambdaMetafactory | |
#71 = NameAndType #76:#80 // metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; | |
#72 = NameAndType #20:#21 // f1:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#73 = NameAndType #22:#21 // f2:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#74 = NameAndType #23:#21 // lambda$main$0:(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
#75 = Utf8 java/lang/invoke/LambdaMetafactory | |
#76 = Utf8 metafactory | |
#77 = Class #82 // java/lang/invoke/MethodHandles$Lookup | |
#78 = Utf8 Lookup | |
#79 = Utf8 InnerClasses | |
#80 = Utf8 (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; | |
#81 = Class #83 // java/lang/invoke/MethodHandles | |
#82 = Utf8 java/lang/invoke/MethodHandles$Lookup | |
#83 = Utf8 java/lang/invoke/MethodHandles | |
{ | |
Foo(); | |
descriptor: ()V | |
flags: | |
Code: | |
stack=1, locals=1, args_size=1 | |
0: aload_0 | |
1: invokespecial #1 // Method java/lang/Object."<init>":()V | |
4: return | |
LineNumberTable: | |
line 2: 0 | |
public static void main(java.lang.String[]); | |
descriptor: ([Ljava/lang/String;)V | |
flags: ACC_PUBLIC, ACC_STATIC | |
Code: | |
stack=4, locals=5, args_size=1 | |
0: new #2 // class Foo | |
3: dup | |
4: invokespecial #3 // Method "<init>":()V | |
7: astore_1 | |
8: invokedynamic #4, 0 // InvokeDynamic #0:apply:()Ljava/util/function/BiFunction; | |
13: astore_2 | |
14: aload_1 | |
15: dup | |
16: invokevirtual #5 // Method java/lang/Object.getClass:()Ljava/lang/Class; | |
19: pop | |
20: invokedynamic #6, 0 // InvokeDynamic #1:apply:(LFoo;)Ljava/util/function/BiFunction; | |
25: astore_3 | |
26: invokedynamic #7, 0 // InvokeDynamic #2:apply:()Ljava/util/function/BiFunction; | |
31: astore 4 | |
33: getstatic #8 // Field java/lang/System.out:Ljava/io/PrintStream; | |
36: aload_2 | |
37: iconst_3 | |
38: invokestatic #9 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
41: iconst_5 | |
42: invokestatic #9 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
45: invokeinterface #10, 3 // InterfaceMethod java/util/function/BiFunction.apply:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
50: invokevirtual #11 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V | |
53: getstatic #8 // Field java/lang/System.out:Ljava/io/PrintStream; | |
56: aload_3 | |
57: iconst_4 | |
58: invokestatic #9 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
61: bipush 6 | |
63: invokestatic #9 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
66: invokeinterface #10, 3 // InterfaceMethod java/util/function/BiFunction.apply:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
71: invokevirtual #11 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V | |
74: getstatic #8 // Field java/lang/System.out:Ljava/io/PrintStream; | |
77: aload 4 | |
79: iconst_5 | |
80: invokestatic #9 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
83: bipush 9 | |
85: invokestatic #9 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
88: invokeinterface #10, 3 // InterfaceMethod java/util/function/BiFunction.apply:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; | |
93: invokevirtual #11 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V | |
96: return | |
LineNumberTable: | |
line 4: 0 | |
line 5: 8 | |
line 6: 14 | |
line 7: 26 | |
line 8: 33 | |
line 9: 53 | |
line 10: 74 | |
line 11: 96 | |
private static java.lang.Integer f1(java.lang.Integer, java.lang.Integer); | |
descriptor: (Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
flags: ACC_PRIVATE, ACC_STATIC | |
Code: | |
stack=2, locals=2, args_size=2 | |
0: aload_0 | |
1: invokevirtual #12 // Method java/lang/Integer.intValue:()I | |
4: aload_1 | |
5: invokevirtual #12 // Method java/lang/Integer.intValue:()I | |
8: imul | |
9: invokestatic #9 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
12: areturn | |
LineNumberTable: | |
line 13: 0 | |
private java.lang.Integer f2(java.lang.Integer, java.lang.Integer); | |
descriptor: (Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
flags: ACC_PRIVATE | |
Code: | |
stack=2, locals=3, args_size=3 | |
0: aload_1 | |
1: invokevirtual #12 // Method java/lang/Integer.intValue:()I | |
4: aload_2 | |
5: invokevirtual #12 // Method java/lang/Integer.intValue:()I | |
8: imul | |
9: invokestatic #9 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
12: areturn | |
LineNumberTable: | |
line 16: 0 | |
private static java.lang.Integer lambda$main$0(java.lang.Integer, java.lang.Integer); | |
descriptor: (Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer; | |
flags: ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC | |
Code: | |
stack=2, locals=2, args_size=2 | |
0: aload_0 | |
1: invokevirtual #12 // Method java/lang/Integer.intValue:()I | |
4: aload_1 | |
5: invokevirtual #12 // Method java/lang/Integer.intValue:()I | |
8: imul | |
9: invokestatic #9 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; | |
12: areturn | |
LineNumberTable: | |
line 7: 0 | |
} |
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
import java.util.function.BiFunction; | |
class Foo { | |
public static void main(String[] args) { | |
Foo o = new Foo(); | |
BiFunction<Integer, Integer, Integer> ff1 = Foo::f1; | |
BiFunction<Integer, Integer, Integer> ff2 = o::f2; | |
BiFunction<Integer, Integer, Integer> ff3 = (x, y) -> x * y; | |
System.out.println(ff1.apply(3, 5)); // => 15 | |
System.out.println(ff2.apply(4, 6)); // => 24 | |
System.out.println(ff3.apply(5, 9)); // => 45 | |
} | |
private static Integer f1(Integer x, Integer y) { | |
return x * y; | |
} | |
private Integer f2(Integer x, Integer y) { | |
return x * y; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment