```inline fun SearchView.onQueryTextChanged(crossi...
# announcements
f
Copy code
inline fun SearchView.onQueryTextChanged(crossinline listener: (String) -> Unit) {
    this.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
        override fun onQueryTextSubmit(query: String?): Boolean {
            return true
        }

        override fun onQueryTextChange(newText: String?): Boolean {
            listener(newText.orEmpty())
            return true
        }
    })
}
Do I understand that correctly, the
crossinline
modifier assures that we can't call return in the lambda we are passing to this function? Because if we don't call
return
here, we would leave the
onQueryTextChange
method.
a
Return from
onQueryTextChange
should not happen iirc, but always do
Tools -> Kotlin -> Show Kotlin Bytecode -> Decompile to Java
for complete sure(ity). Create a check with a test lambda and decompile !
f
I decompiled the code but I don't understand it
that's why I'm asking for a verification of my understanding
l
Yep, the compiler prevents the passed
listener
to have suspend calls and return expressions.
listener
can still throw theoretically though.
f
thank you