Reputation: 23
Got problems with RecyclerAdapter ViewHolder
abstract class ExpandableRecyclerAdapter<T : ExpandableRecyclerAdapter.ListItem>(private val context: Context) : RecyclerView.Adapter<ExpandableRecyclerAdapter.ViewHolder>() {
protected var allItems = ArrayList<T>()
...
open inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
open class ListItem(val itemType: Int = 0)
}
ExpandableRecyclerAdapter in <...>
is underlined with error:
One type argument expected for class ExpandableRecyclerAdapter< T : ExpandableRecyclerAdapter.ListItem>
However, if I declare my ViewHolder class as static (by removing inner), the error disappears, but it is unacceptable for me.
Advices like here are not going to be helpful: Kotlin One type argument expected for class for abstract generic view holder
Appreciate the help!
Upvotes: 2
Views: 7639
Reputation: 25573
Kotlin does not allow generic types to be specified without providing generics unless you're referring to a non-instance member of the class. (static inner classes, ::class
, companion methods). Since ViewHolder
is an inner class its identity depends on the exact specification of its outer class when talking about the type itself.
This means you cannot refer to a generic ExpandableRecyclerAdapter.ViewHolder
, you must specify the bounds in which the outer class lies as well. Changing it to ExpandableRecyclerAdapter<T>.ViewHolder
should solve the issue.
Upvotes: 7