Search code examples
androidfunctionkotlinunderscores

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

Solution

  • 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