First, add org.jetbrains.kotlinx:kotlinx-coroutines-jdk8
module to your dependencies. In your Kotlin file define the following async function that corresponds to Java style of writing async APIs:
fun doSomethingAsync(): CompletableFuture<List<MyClass>> =
GlobalScope.future { doSomething() }
Now use doSomethingAsync
from Java in the same way as you are using other asynchronous APIs in the Java world.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…