Can't override methods with complex generic params

Fire .2505

I’m trying to use FlexibleAdapter with Fire. FlexibleAdapter makes it very easy to create RecyclerView based UITableView and UICollectionView-like Android counterparts.

The problem is, I can’t override some methods in the attached project, because I get the Generic parameter doesn’t fulfill constraint compile time error.

I have a class defined as:

public class TableViewHeader: AbstractHeaderItem<TableViewItemHolder>

where I have to override bindViewHolder and createViewHolder methods in order to be able to use it.

Two problems:

First, for both methods Fire CC offers me the following definitions:

func bindViewHolder(_ arg1: FlexibleAdapter<IFlexible<VH>!>!, _ arg2: VH!, _ arg3: Int32, _ arg4: List<Object!>!)
func createViewHolder(_ arg1: View!, _ arg2: FlexibleAdapter<IFlexible<VH>!>!) -> VH!

VH kind of makes sense because IFlexible is defined as:

public interface IFlexible<VH extends RecyclerView.ViewHolder>

However, the compiler complains about VH being unknown type. IMHO it would make more sense for the CC to replace VH with TableViewItemHolder given the TableViewHeader definition above.

This brings us to the second issue. If I replace VH with TableViewItemHolder, the compiler says Generic parameter doesn't fulfill constraint which shouldn’t be because TableViewItemHolder is descendant of RecyclerView.ViewHolder.

Test project attached.

FlexibleAdapter test.zip (3.8 MB)

Thanks, logged as bugs://84271

Oddly, I get 5 predex errors with this:

dex: processing androidx/appcompat/graphics/drawable/DrawableContainer$BlockInvalidateCallback.class...
dex: processing org/java_websocket/exceptions/InvalidDataException.class...
dex: processing org/java_websocket/exceptions/InvalidEncodingException.class...
dex: processing org/java_websocket/exceptions/InvalidFrameException.class...
dex: processing org/java_websocket/exceptions/InvalidHandshakeException.class...

ignoring those, can reproduced your error. it seems you’re missing a constraint? but I logged an issue, as this is inscrutable for me, so at the very pleats this needs better messages…

AFAIK RecyclerView.ViewHolder is the constraint and TableViewItemHolder descends from it, so I can’t figure out what else I might be missing. I tried many things but nothing worked.

Android Studio version of this project compiles fine and Kotlin version of the methods, as suggested by Android Studio CC, looks pretty clean:

override fun bindViewHolder(anAdapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?, aHolder: TableViewItemHolder?,
                            aPosition: Int, aPayloads: MutableList<Any>?) {
}

override fun createViewHolder(aView: View?, anAdapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?): TableViewItemHolder {
    return TableViewItemHolder(aView, anAdapter, false)
}

override fun unbindViewHolder(anAdapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?, aHolder: TableViewItemHolder?,
                              aPosition: Int) {
}

And by converting to Swift as below I still get the same Generic parameter doesn’t fulfill constraint error:

override func bindViewHolder(_ anAdapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?, _ aHolder: TableViewItemHolder?,
                            _ aPosition: Int, _ aPayloads: List<Object>?) {
}

override func createViewHolder(_ aView: View?, _ anAdapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?) -> TableViewItemHolder {
    return TableViewItemHolder(aView, anAdapter, false)
}

override func unbindViewHolder(_ anAdapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?, _ aHolder: TableViewItemHolder?,
_ aPosition: Int) {
}