Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Kotlin function with function as parameter in Java Code?

I have a kotlin method as follows:

fun methodWithCallBackAsParameter(callback:() -> Unit) {
    //Do Somejob
    callback()
}

In kotlin we simply use this method with following syntax:

methodWithCallBackAsParameter {
    //Some Instructions here.
}

Now I want to use this Kotlin method in a Java class but I am not able to figure out how.

like image 678
Prajeet Shrestha Avatar asked Oct 11 '25 15:10

Prajeet Shrestha


1 Answers

Just return Unit.INSTANCE in the end of the lambda expression.

like image 149
nyarian Avatar answered Oct 14 '25 03:10

nyarian