https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

theapache64

06/18/2021, 10:07 AM
I am wondering if we can implement a
suspend
method in Java class. What's the correct way to do it? SO Thread: https://stackoverflow.com/questions/68032757/how-can-i-implement-kotlin-suspend-method-in-a-java-class
d

diesieben07

06/18/2021, 10:08 AM
You really shouldn't, to be honest. If you want Java interop you need to design your APi in a Java-compatible way,
suspend
functions aren't. Provide a
CompletableFuture
based version for Java.
✔️ 3
c

CLOVIS

06/19/2021, 7:55 AM
Note that you won't be able to call suspend functions easily from Java, even inside a suspend function: you need to pass the correct parameter to the Continuation, and handle the callbacks yourself. It's fairly complicated
3 Views