It seems like I don't fully understand SAM interfa...
# getting-started
f
It seems like I don't fully understand SAM interfaces in Kotlin yet. On one hand, interfaces in Java classes work just fine:
Copy code
chartViewHolder.container?.setOnClickListener {
    onArtistClickListener?.onArtistClick(artists[chartViewHolder.adapterPosition])
}
However when I try to set
onArtistClickListener
(a var) in the adapter it just fails. This is the Kotlin interface:
Copy code
interface OnArtistClickListener {
    fun onArtistClick(artistModel: ArtistModel)
}
And this is how I'd expect to be able to set it:
Copy code
chartAdapter.onArtistClickListener = { Timber.d("Start new controller for $it") }
But it says it found
() -> Unit
and requires
ChartAdapter.OnArtistClickListener?
. So this (http://stackoverflow.com/questions/26507099/lambda-expressions-in-kotlin) post seems to explain why this is, but I'm not quite sure what it would actually look like then with
() -> Unit
. Any advice?