I have these three helper extensions:
fun <T, K : BaseViewHolder> BaseQuickAdapter<T, K>.onItemClick(
onItemClick: (adapter: BaseQuickAdapter<*, *>, position: Int, item: T) -> Unit
): BaseQuickAdapter<T, K> {
setOnItemClickListener { adapter, _, position ->
onItemClick(adapter, position, data[position])
}
return this
}
fun <T, K : BaseViewHolder> BaseQuickAdapter<T, K>.onItemClick(
onItemClick: (position: Int, item: T) -> Unit
): BaseQuickAdapter<T, K> =
onItemClick { _, position, item -> onItemClick(position, item) }
fun <T, K : BaseViewHolder> BaseQuickAdapter<T, K>.onItemClick(
onItemClick: (item: T) -> Unit
): BaseQuickAdapter<T, K> =
onItemClick { _, item -> onItemClick(item) }
every onItemClick
function takes one argument less that the previous one
when I call:
onItemClick { item ->
}
everything works fine as expected and the last method is called.
but when I remove the explicit item
ad try to use it
onItemClick {
it.doStuff()
}
I get this error:
Cannot choose among the following candidates without completing type inference:
public fun <T, K : BaseViewHolder> BaseQuickAdapter<T#1 (type parameter of humazed.github.com.kotlinandroidutils.simpleAdapter), KBaseViewHolder>.onItemClick(onItemClick: (adapter: BaseQuickAdapter<*, *>, position: Int, item: T#1) → Unit): BaseQuickAdapter<T#1, KBaseViewHolder> defined in humazed.github.com.kotlinandroidutils
public fun <T, K : BaseViewHolder> BaseQuickAdapter<T#1, KBaseViewHolder>.onItemClick(onItemClick: (item: T#1) → Unit): BaseQuickAdapter<T#1, KBaseViewHolder> defined in humazed.github.com.kotlinandroidutils
public fun <T, K : BaseViewHolder> BaseQuickAdapter<T#1, KBaseViewHolder>.onItemClick(onItemClick: (position: Int, item: T#1) → Unit): BaseQuickAdapter<T#1, KBaseViewHolder> defined in humazed.github.com.kotlinandroidutils
the full code on GitHub
I'm aware there are similar questions on SOF but they are not the same as mine and the answers don't apply here.