It wasn't long after I started studying Kotlin.
There are parts that I don't understand about the delivery of lambda expressions in the Android listener.
In JAVA
botton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
i understand this code.
I understand this code. An anonymous object is created and passed as a parameter of setOnClickListener.
In Kotlin
button.setOnClickListener(object: View.OnClickListener {
override fun onClick(p0: View?) {
TODO("Not yet implemented")
}
})
And I understand this code too. I understand it as it is a way to create anonymous objects similar to Java.
But
In Lamda of Kotlin
button?.setOnClickListener { }
I don't understand how this code works.
The lambda expressed here should be passed as an argument of setOnClickListener.
onClick() is an implementation function of the OnClickListener interface, how is it possible to be passed to setOnClickListener?
I don't understand well.
Isn't setOnClickListener an OnClickListener interface object that should be passed?