Everybody, I got a question about lambda and SAM c...
# getting-started
f
Everybody, I got a question about lambda and SAM conversion. The subject is Android here, but my question is actually Kotlin related so I post here. Why if I do use the "lambda version" to override the single interface method ( top in the image) I don't have to declare the "object: " explicitly, while if I try to explicitly override the single method, I have to? Thanks 😄
f
Thanks, I read that; but I still miss it. I likely am not skilled enough to understand it. I'll try to dig deeper.
k
What you have right now is the point: the first code is just syntax sugar for the second code, they're equivalent.
s
Just to add to what @karelpeeters said. The only reason you can do it is because the
OnClickListener
is a Java interface. For some reason it is not allowed for kotlin interfaces.
f
It would be interesting to know why then. It could be very handy nevertheless.
k
For Kotlin code you'd just use a function type, eg.
(Event) -> Boolean
so no need for SAM conversion. There's an open youtrack issue about it though.