Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A lambda that takes no parameters

Tags:

kotlin

In Kotlin I would like to create a lambda that takes no parameters and returns nothing. I know how to do this when it takes a string parameter and returns nothing:

private var mOnTextWatcherCallback: ((m: String) -> Unit)? = null

But how do I do it for no parameters?

like image 751
Johann Avatar asked Jan 25 '26 03:01

Johann


1 Answers

Just use empty parentheses:

private var mOnTextWatcherCallback: (() -> Unit)? = null
//                                   ^^                             
like image 164
Robby Cornelissen Avatar answered Jan 29 '26 05:01

Robby Cornelissen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!