Benny老师,我在构造方法里传入RecyclerView.Adapter类型的参数,如果是Java,参数定义为RecyclerView.Adapter即可,而Kotlin没有Raw类型,参数定义为RecyclerView.Adapter<*>或RecyclerView.Adapter<out RecyclerView.ViewHolder>,在调用实参的onBindViewHolder(...)方法会报错:
Out-projected type 'RecyclerView.Adapter<out RecyclerView.ViewHolder>' prohibits the use of 'public abstract fun onBindViewHolder(p0: VH!, p1: Int): Unit defined in android.support.v7.widget.RecyclerView.Adapter'
代码情况如下:
class HeaderAndFooterWrapper(private val innerAdapter: RecyclerView.Adapter<*>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, pos: Int) { if (isHeaderViewPos(pos)) return if (isFooterViewPos(pos)) return innerAdapter.onBindViewHolder(holder, pos - headersCount) } }
如何解决innerAdapter.onBindViewHolder报错问题呢?