Pranciskus
Pranciskus

Reputation: 539

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
            }
        }

Upvotes: 4

Views: 3386

Answers (2)

harry
harry

Reputation: 261

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
        }

Upvotes: 1

AskNilesh
AskNilesh

Reputation: 69689

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

Upvotes: 8

Related Questions