Skip to content

Instantly share code, notes, and snippets.

@chao2zhang
Last active November 27, 2019 20:32
Show Gist options
  • Save chao2zhang/dace2f3972d8ea9d0c1a56bc5d1b1cd7 to your computer and use it in GitHub Desktop.
Save chao2zhang/dace2f3972d8ea9d0c1a56bc5d1b1cd7 to your computer and use it in GitHub Desktop.
JavaCode consuming Kotlin Function
// KotlinApp.kt
typealias KotlinFunction = (Int) -> Boolean
fun invokeKotlinFunction(id: Int, f: KotlinFunction) = f(id)
// JavaApp.java
private void useKotlinFunction()
Function1<Integer, Boolean> kotlinFunc = id -> id % 2 == 0;
KotlinAppKt.invokeKotlinFunction(3, id -> id % 2 == 0);
KotlinAppKt.invokeKotlinFunction(4, this::isEven);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment