juliocbcotta
06/13/2022, 7:22 AMfun translate(key: String, body: (translation: String) -> Unit)
and I need to integrate it with Java files, which requires me to return Unit.INSTANCE;
like:
translate("MY_KEY", translate -> {
// Do something
return Unit.INSTANCE;
});
Is it possible to avoid the return statement by changing the method signature or something ?ephemient
06/13/2022, 7:30 AMCallable<String> instead of (String) -> Unitephemient
06/13/2022, 7:32 AMjuliocbcotta
06/13/2022, 7:36 AMCallable<String> is more like () -> String , not (String) -> Unitjuliocbcotta
06/13/2022, 7:36 AMephemient
06/13/2022, 7:40 AMConsumer<String>Klitos Kyriacou
06/13/2022, 7:43 AMUnit.INSTANCE defined in Kotlin (as far as I know). Unit is defined as an object, i.e. there is a singleton class called Unit (corresponding to Java's void) and there is only one instance of that class, also called Unit. You don't need to return anything in a function declared as returning Unit, as your function will implicitly return the instance Unit.ephemient
06/13/2022, 7:44 AM@JvmName("-translate") // hide from Java
fun translate(key: String, body: (String) -> Unit)
@Deprecated(message = "for Java only", level = DeprecationLevel.HIDDEN)
fun translate(key: String, body: Consumer<String>)ephemient
06/13/2022, 7:46 AMKlitos Kyriacou
06/13/2022, 7:47 AMephemient
06/13/2022, 7:47 AMephemient
06/13/2022, 7:50 AM