Last active
November 26, 2019 07:07
-
-
Save chao2zhang/42c16547b32e67093d0f7b38c7fa417d to your computer and use it in GitHub Desktop.
KotlinApp.kt : Kotlin -> Java
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
fun isEven(id: Int) = id % 2 == 0 | |
fun invokeJavaSam(id: Int, sam: JavaSam) = sam.apply(id) | |
fun useJavaSam() { | |
val javaSam = JavaSam { id -> id % 2 == 0 } | |
invokeJavaSam(3, JavaSam { id -> id % 2 == 0 }) | |
invokeJavaSam(4, JavaSam { isEven(it) }) | |
// public boolean invokeJavaSam(int id, JavaSam sam); | |
JavaApp().invokeJavaSam(3) { id -> id % 2 == 0 } | |
JavaApp().invokeJavaSam(4, ::isEven) | |
JavaApp().invokeJavaSam(4) { isEven(it) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment