Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not enough information to infer type variable T

I have updated today my build.gradle file to the latest version
classpath 'com.android.tools.build:gradle:3.6.3' and the latest ext.kotlin_version = '1.3.72' and I get the following error that is in the title at: instance().

private val viewModelFactory: ListViewModelFactory by instance()

This is my Factory class:

class ListViewModelFactory(
    private val listRepository: ListRepository
) : ViewModelProvider.NewInstanceFactory() {

    @Suppress("UNCHECKED_CAST")
    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        return ListViewModel(listRepository) as T
    }
}

Can someone explain why this occurred and how can I get rid of the error. Thank you in advance!

P.S. if it is of any help I use kodein and here is my bind

bind() from provider { ListViewModelFactory(instance()) }
like image 329
CasGab Avatar asked Apr 21 '20 07:04

CasGab


2 Answers

can you try
private val viewModelFactory by instance<ListViewModelFactory>()

like image 176
Asterisk Avatar answered Nov 14 '22 22:11

Asterisk


Try this : Replace

 private val factory : AuthViewModelFactory by instance()

to

  private val factory by instance<AuthViewModelFactory>()
like image 26
Sathish Gadde Avatar answered Nov 14 '22 22:11

Sathish Gadde