0

This is my method:

abstract class BaseFragmentKey<T : Fragment> : Parcelable {
     fun newFragment(): T {
        val fragment = createFragment()
        val bundle = Bundle()
        bundle.putParcelable("KEY", this)
        fragment.arguments = bundle
        return fragment
    }

    protected abstract fun createFragment(): T

    @CallSuper
    open fun updateExistingFragment(fragment: T): T {
        return fragment
    }
}

But when I try to call with a Fragment:

   newFragment = newKey.updateExistingFragment(existingFragment)

It says before compiling that Type mismatch. Required Nothing, found Fragment. If I do existingFragment as Nothing it crashes cause I cannot cast to null.

How can I fix this?

enter image description here

rosu alin
  • 5,674
  • 11
  • 69
  • 150

1 Answers1

1

The problem in wildcard in stateChange.getNewState<BaseFragmentKey<*>>. It should be for example stateChange.getNewState<BaseFragmentKey<Fragment>>

Andrei Tanana
  • 7,932
  • 1
  • 27
  • 36