https://kotlinlang.org logo
Title
a

am

06/23/2019, 10:58 AM
How do we add generic class as Map value ? I am defining class named
abstract class CardHolder<T:RecyclerView.ViewHolder>{

    lateinit var actionListener: CardActionListener

    abstract fun onCreateViewHolder(parent: ViewGroup): T

    abstract fun onBindViewHolder(holder:T, card: Card, position: Int)
}
which will be extended to do inflationa and other formalities to display data,
class NewCardDelegate:CardViewHolder<NewHolder>{
	//Rest of code
}
the reason I was doing this so that I could define a mutableMap<Int,CardHolder> and reduce the Adapter class
val map =mutableMapOf<Int,CardHolder>
map[25] = NewCard() //error
but it seems like its not right way Please guide me for any other better way
k

karelpeeters

06/23/2019, 11:00 AM
You need
CardHolder<*>
as the map value type.
a

am

06/23/2019, 11:08 AM
ooh what is this term called @karelpeeters
*