How do I call Kotlin functions with lambdas in the parameter from a Java class.
Example
fun getToken(
tokenUrl: String,
onSuccess: (String) -> Unit,
onError: (Error) -> Unit
): Provider {
//Implementation
}
You can do this
value.getToken("url",
new Function1<String, Unit>() {
@Override
public Unit invoke(String s) {
/* TODO */
return Unit.INSTANCE;
}
}, new Function1<Throwable, Unit>() {
@Override
public Unit invoke(Throwable throwable) {
/* TODO */
return Unit.INSTANCE;
}
});
You can call it with normal Java 8 lambdas, since Kotlin is actually using a single-method interface on the backend.
myFoo.getToken(tokenUrl, successString -> { ... }, error -> { ... });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With