Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What means "_" symbol in Kotlin?

I tried to find information what it means but I didn't. Trying to understand what it does in this code:

checkBox.setOnCheckedChangeListener { _, isChecked ->
            if (isChecked) {
                // The toggle is enabled
            } else {
                // The toggle is disabled
            }
        }
like image 385
Pranciskus Avatar asked Oct 29 '25 08:10

Pranciskus


2 Answers

The _ Used for

  • substitutes an unused parameter in a lambda expression
  • substitutes an unused parameter in a destructuring declaration

For more information check this Keywords and Operators

like image 126
AskNilesh Avatar answered Oct 31 '25 01:10

AskNilesh


when user does't need a parameter in lembda expression then we can use "_"

 setOnTouchListener { _, p1 ->
            if (p1.action == MotionEvent.ACTION_DOWN) {
                hideKeyboard()
                true
            } else
                false
        }
like image 40
harry Avatar answered Oct 30 '25 23:10

harry



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!