I am trying to use Hilt to inject a generic interface implementation but it keep gives me errors
My interface looks like this:
interface Validator<in T> {
fun validate(value: T): Boolean
}
And a typical implementation of it can be like this:
class FullNameValidator @Inject constructor() : Validator<String>{
override fun validate(value: String): Boolean {
val isValid = //Validation logic
return isValid
}
}
Now the way I am trying to use Hilt, i've tried to use @Bind method in a @Module like this
@Binds
abstract fun bindFullNameValidator(validator: FullNameValidator) : Validator<String>
Like i am doing with all interfaces implementations and its working just fine
But here, Hilt claims that it cannot find a way to inject the String object which is the generic type.
Is there a proper way to inject such interface
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…