can someone point me to some information on callin...
# coroutines
j
can someone point me to some information on calling a
suspend fun
from a java class with Java 7 compatibility? I found some information by googling on how to do this with Java 8+, but not Java 7
g
Why do you need this?
In theory it’s possible, but it’s very-very unpleasant to use, and may make sense only for some interop library
Java 8 version also shouldn’t be different from Java 7 (maybe except lambdas)
j
CompletableFuture seems to be the way to do it, and it's an Android (pre-API 24) project, so CompletableFuture doesn't exist
s
Yeah... You'd have to write your own Java-compatible shim/adapter around your API's suspend funs, using Rx or plain callbacks or other mechanisms.
g
Yes, if you just want to provide way to use coroutines from Java, use any Java library
RxJava, CompletableFuture, ListenableFuture (a part of guava), you can write even own abstraction, if you want and easily write adapter for it
d
You can call it with reflection if you add the continuation parameter and implement the logic for the return value.
I don't think suspend function names are mangled but based on the answers in the thread I guess you can't just call it normally with the continuation 🤔 Maybe it's difficult to work with the Result type from java as well.