Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lambda comparison between Java and Kotlin
public class JavaLambdaTest
{
public int i;
public void runTask(Runnable f)
{
f.run();
}
public void run()
{
runTask(() -> i += 1);
}
}
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
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;
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