inline fun sum(a: Int, b: Int, lambda: (result: Int) -> Unit, noinline lambda2: (result: Int) -> Unit): Int { val r = a + b lambda.invoke(r) lambda2.invoke(r) return r }
fun main(args: Array<String>) { sum(1, 2, { println("Result is: $it") }, { println("Invoke lambda2: $it") } ) }
//反编译为 Java
public static final int sum(int a, int b, @NotNull Function1 lambda, @NotNull Function1 lambda2) { int r = a + b; lambda.invoke(r); lambda2.invoke(r); return r; }
public static final void main(@NotNull String[] args) { byte a$iv = 1; byte b$iv = 2; Function1 lambda2$iv = (Function1)null.INSTANCE; int r$iv = a$iv + b$iv; String var8 = "Result is: " + r$iv; System.out.println(var8); lambda2$iv.invoke(r$iv); }