-
-
Save anonymous/e1d0e3d5f05688986018 to your computer and use it in GitHub Desktop.
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
public class Lambda { | |
interface NotRunnable { | |
void notRun(); | |
} | |
private final Runnable r = () -> { | |
System.out.println("Hello"); | |
}; | |
private final NotRunnable r2 = r::run; | |
} | |
================================================================== | |
$ javap -p -c Lambda.class | |
Compiled from "Lambda.java" | |
public class Lambda { | |
private final java.lang.Runnable r; | |
private final Lambda$NotRunnable r2; | |
public Lambda(); | |
Code: | |
0: aload_0 | |
1: invokespecial #1 // Method java/lang/Object."<init>":()V | |
4: aload_0 | |
/* vvv here it creates a dynamic implementation of Runnable */ | |
5: invokedynamic #2, 0 // InvokeDynamic #0:run:()Ljava/lang/Runnable; | |
10: putfield #3 // Field r:Ljava/lang/Runnable; | |
13: aload_0 | |
14: aload_0 | |
15: getfield #3 // Field r:Ljava/lang/Runnable; | |
18: dup | |
19: invokevirtual #4 // Method java/lang/Object.getClass:()Ljava/lang/Class; | |
22: pop | |
/* vvv here it creates a dynamic implementation of NotRunnable */ | |
23: invokedynamic #5, 0 // InvokeDynamic #1:notRun:(Ljava/lang/Runnable;)LLambda$NotRunnable; | |
28: putfield #6 // Field r2:LLambda$NotRunnable; | |
31: return | |
/** vvv this is the code for both run() and notRun(). What is "this" in this piece of bytecode? */ | |
private static void lambda$new$0(); | |
Code: | |
0: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; | |
3: ldc #8 // String Hello | |
5: invokevirtual #9 // Method java/io/PrintStream.println:(Ljava/lang/String;)V | |
8: return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment