# Issue with RecyclerView.Adapter\<\> and Kotlin Generics

**URL:** <https://discuss.kotlinlang.org/t/issue-with-recyclerview-adapter-and-kotlin-generics/8342>\
**Category:** Android\
**Created:** [June 29, 2018, 9:42pm UTC](https://discuss.kotlinlang.org/t/issue-with-recyclerview-adapter-and-kotlin-generics/8342 "2018-06-29T21:42:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mitenko.david](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mitenko.david/32/5283_2.png) [@mitenko.david](https://discuss.kotlinlang.org/u/mitenko.david)\
**Post date:** [June 29, 2018, 9:42pm UTC](https://discuss.kotlinlang.org/t/issue-with-recyclerview-adapter-and-kotlin-generics/8342/1 "2018-06-29T21:42:02Z")

</div>

Hi all,

This was originally posted over in [stackoverflow](https://stackoverflow.com/questions/51049049/out-projected-type-prohibits-the-use-of-method), perhaps you could help me here?

I can’t seem to wrap my head around Kotlin generics, please help

I read [here](https://stackoverflow.com/questions/40519921/out-projected-type-arraylist-prohibits-the-use-of-public-open-fun-addinde/40520344) and [here](https://kotlinlang.org/docs/reference/generics.html) and I still can’t determine how to make this work. I have a RecyclerView adapter that uses an abstracted parent BaseFieldVH as the ViewHolder class.

So the Adapter class looks like this:

```
class MyAdapter() : RecyclerView.Adapter<BaseFieldVH<*>>() {
... 
    override fun onBindViewHolder(holder: BaseFieldVH<*>, position: Int) {
        holder.bind(data[position])
    }
}

```

And the ViewHolder implementation looks like this:

```
abstract class BaseFieldVH<in FF : BaseFormField>
    (itemView: View) : RecyclerView.ViewHolder(itemView) {
    ...
    abstract fun bind(formField: FF)
}

```

But the actual call to `holder.bind(data[position])` is displaying the error:

```
Out-projected type 'BaseFieldVH<*>' prohibits the use of 'public 
abstract fun bind(formField: FF): Unit defined in ...

```

**use in Nothing?**

I’ve also tried defining the Adapter with `BaseFieldVH<in Nothing>` but then I get a Type Mismatch error for attempting to put Nothing into a function that requires a BaseFormField.

**use BaseFormField**

Defining the Adapter with `BaseFieldVH<iBaseFormField>` actually resolves the binding issue, but then in the onCreateViewHolder there is a type mismatch for the view holders:

```
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseFieldVH<BaseFormField> {
    val itemView: View
    when (viewType) {
        HEADER_TYPE -> {
            itemView = LayoutInflater.from(parent.context)
                    .inflate(R.layout.item_header, parent, false)
            return HeaderVH(itemView)
        }

```

HeaderVH is an extension of BaseFieldVH, and so there’s a type mismatch

---

<div class="post-metadata">

**Author:** ![Svyatoslav.Scherbina](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@Svyatoslav.Scherbina](https://discuss.kotlinlang.org/u/Svyatoslav.Scherbina)\
**Post date:** [December 13, 2018, 7:40am UTC](https://discuss.kotlinlang.org/t/issue-with-recyclerview-adapter-and-kotlin-generics/8342/2 "2018-12-13T07:40:46Z")

</div>

Hi.

```
override fun onBindViewHolder(holder: BaseFieldVH<*>, position: Int) {
    holder.bind(data[position])
}

```

What type is `data` of?  
How `HeaderVH` is defined?
