我在学习 Kotlin 时在Udacity 项目中遇到了这个自定义 OnClickListener 接口。我明白它在做什么,但我不明白它是如何做到的。有人可以向我解释一下代码吗?
/**
* Custom listener that handles clicks on [RecyclerView] items. Passes the [MarsProperty]
* associated with the current item to the [onClick] function.
* @param clickListener lambda that will be called with the current [MarsProperty]
*/
class OnClickListener(val clickListener: (marsProperty:MarsProperty) -> Unit) {
fun onClick(marsProperty:MarsProperty) = clickListener(marsProperty)
}
Run Code Online (Sandbox Code Playgroud)