When executing a method with a kotlin callback block from Java code, it was necessary to do the following. In the following cases, on the Java side return Unit.INSTANCE; If there is no compilation error, I was wondering what to do just because I was told that the return type of the ramda expression is inconsistent, so I posted it.
kotlin
class KotlinClass {
fun loadItems(itemIds: List<String>,
complete: (isSuccess: Boolean, itemList: List<Item>) -> Unit) {
/*Some processing*/
complete(true, itemList)
}
}
java (caller)
kotlinClass.loadItems(itemIds, (isSuccess, items) -> {
/*Some processing*/
//Note: Finally, Unit.Must return INSTANCE
return Unit.INSTANCE;
})
In kotlin, even if there is no return value of the method, it is actually treated as omitting the return Unit, and it seems that you have to do return Unit.INSTANCE; in order to maintain compatibility with it in Java.
Reference: http://stackoverflow.com/questions/37828790/why-do-i-have-to-return-unit-instance-when-implementing-in-java-a-kotlin-functio