Last active
October 15, 2017 15:26
-
-
Save komamitsu/65c14c3d5dd873fbb5a03341749d156f to your computer and use it in GitHub Desktop.
Lambda comparison between Java and Kotlin
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 JavaLambdaTest | |
{ | |
public int i; | |
public void runTask(Runnable f) | |
{ | |
f.run(); | |
} | |
public void run() | |
{ | |
runTask(() -> i += 1); | |
} | |
} |
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 final void runTask(kotlin.jvm.functions.Function0<kotlin.Unit>); | |
descriptor: (Lkotlin/jvm/functions/Function0;)V | |
flags: ACC_PUBLIC, ACC_FINAL | |
Code: | |
stack=2, locals=2, args_size=2 | |
0: aload_1 | |
1: ldc #20 // String f | |
3: invokestatic #26 // Method kotlin/jvm/internal/Intrinsics.checkParameterIsNotNull:(Ljava/lang/Object;Ljava/lang/String;)V | |
6: aload_1 | |
7: invokeinterface #32, 1 // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object; | |
12: pop | |
13: return | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 14 0 this Lorg/komamitsu/tinylisp/KotlinLambdaTest; | |
0 14 1 f Lkotlin/jvm/functions/Function0; | |
LineNumberTable: | |
line 7: 6 | |
line 8: 13 | |
Signature: #65 // (Lkotlin/jvm/functions/Function0<Lkotlin/Unit;>;)V | |
RuntimeInvisibleParameterAnnotations: | |
0: | |
0: #18() | |
public final void run(); | |
descriptor: ()V | |
flags: ACC_PUBLIC, ACC_FINAL | |
Code: | |
stack=4, locals=1, args_size=1 | |
0: aload_0 | |
1: new #37 // class org/komamitsu/tinylisp/KotlinLambdaTest$run$1 | |
4: dup | |
5: aload_0 | |
6: invokespecial #41 // Method org/komamitsu/tinylisp/KotlinLambdaTest$run$1."<init>":(Lorg/komamitsu/tinylisp/KotlinLambdaTest;)V | |
9: checkcast #28 // class kotlin/jvm/functions/Function0 | |
12: invokevirtual #43 // Method runTask:(Lkotlin/jvm/functions/Function0;)V | |
15: return | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 16 0 this Lorg/komamitsu/tinylisp/KotlinLambdaTest; | |
LineNumberTable: | |
line 11: 0 | |
line 12: 15 |
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 void runTask(java.lang.Runnable); | |
descriptor: (Ljava/lang/Runnable;)V | |
flags: ACC_PUBLIC | |
Code: | |
stack=1, locals=2, args_size=2 | |
0: aload_1 | |
1: invokeinterface #2, 1 // InterfaceMethod java/lang/Runnable.run:()V | |
6: return | |
LineNumberTable: | |
line 12: 0 | |
line 13: 6 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 7 0 this Lorg/komamitsu/tinylisp/JavaLambdaTest; | |
0 7 1 f Ljava/lang/Runnable; | |
public void run(); | |
descriptor: ()V | |
flags: ACC_PUBLIC | |
Code: | |
stack=2, locals=1, args_size=1 | |
0: aload_0 | |
1: aload_0 | |
2: invokedynamic #3, 0 // InvokeDynamic #0:run:(Lorg/komamitsu/tinylisp/JavaLambdaTest;)Ljava/lang/Runnable; | |
7: invokevirtual #4 // Method runTask:(Ljava/lang/Runnable;)V | |
10: return | |
LineNumberTable: | |
line 17: 0 | |
line 18: 10 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 11 0 this Lorg/komamitsu/tinylisp/JavaLambdaTest; | |
private void lambda$run$0(); | |
descriptor: ()V | |
flags: ACC_PRIVATE, ACC_SYNTHETIC | |
Code: | |
stack=3, locals=1, args_size=1 | |
0: aload_0 | |
1: dup | |
2: getfield #5 // Field i:I | |
5: iconst_1 | |
6: iadd | |
7: putfield #5 // Field i:I | |
10: return | |
LineNumberTable: | |
line 17: 0 | |
LocalVariableTable: | |
Start Length Slot Name Signature | |
0 11 0 this Lorg/komamitsu/tinylisp/JavaLambdaTest; |
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
class KotlinLambdaTest { | |
var i: Int = 0 | |
fun runTask(f: () -> Unit) { | |
f.invoke() | |
} | |
fun run() { | |
runTask({ i += 1 }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment