Why all of those final classes needs explicitly specified generic parameter when inheriting from generic class when this type can be guessed from constructor. BaseGenericActivity<This parameter>. There is another problem that if factory method which is sent as parameter has overload, thing get much more messy.
//This is my generic class which needs factory method as input
abstract class BaseGenericActivity<TViewBinding: ViewBinding>(private val viewBindingFactory: ((LayoutInflater) -> TViewBinding)?) {
}
//This works
class FirstFinalClassWithExplicitType: BaseGenericActivity<ActivityMenuBinding>(ActivityMenuBinding::inflate)
//This has two errors:
//1. One type argument expected for class BaseGenericActivity<TViewBinding : ViewBinding>
//2.Overload resolution ambiguity. All these functions match.
//public open fun inflate(inflater: LayoutInflater): ActivityMenuBinding defined in com.xbionicsphere.x_card.databinding.ActivityMenuBinding
//public open fun inflate(inflater: LayoutInflater, parent: ViewGroup?, attachToParent: Boolean): ActivityMenuBinding defined in com.xbionicsphere.x_card.databinding.ActivityMenuBinding
class SecondFinalClassWithExplicitType: BaseGenericActivity(ActivityMenuBinding::inflate)
//This has one error:
//1. One type argument expected for class BaseGenericActivity<TViewBinding : ViewBinding>
class ThirdFinalClassWithExplicitType: BaseGenericActivity(::ExampleFactoryMethodWithoutOverload)
//This has one error:
//1. One type argument expected for class BaseGenericActivity<TViewBinding : ViewBinding>
class FourthFinalClassWithExplicitType: BaseGenericActivity<ActivityMenuBinding>(::ExampleFactoryMethodWithoutOverload)
private fun ExampleFactoryMethodWithoutOverload(inflater: LayoutInflater): ActivityMenuBinding {
return null!!
}