Here's a simplified code of what I am doing:
I have this custom ViewHolder:
open class AsyncViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
....
}
I inherit from above ViewHolder and later on need to create a AsyncCellAdapter of the inherited type. I am doing this using Generics:
abstract class AsyncCellAdapter<T: AsyncCellAdapter.AsyncViewHolder>() : RecyclerView.Adapter<T>(){
....
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): T {
val viewHolder = T(View(parent.context)) //<----------Here's the problem
....
return viewHolder
}
....
}
The problem arises at the T in the line T(View(parent.context))
It gives me error:
Type parameter T cannot be called as function
How do I create an instance of the inherited type using Generics and return that?