Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Problem injecting generics #46

Open
emaleavil opened this issue Aug 16, 2022 · 0 comments
Open

Problem injecting generics #46

emaleavil opened this issue Aug 16, 2022 · 0 comments

Comments

@emaleavil
Copy link

emaleavil commented Aug 16, 2022

Hi,

I am facing problems with kotlin generics that use in or out to specify generics. The case that I was trying to inject is the following:

@Binds
 abstract fun bindAddEntryUseCase(
     useCase: AddEntryUseCase
 ): UseCase<AddEntry, Result<Unit>>
@HiltViewModel
class AddViewModel @Inject constructor(
    @AddUseCase private val useCase: UseCase<AddEntry, Result<Unit>>
) : ViewModel() { ... }
class AddEntryUseCase @Inject constructor() : UseCase<AddEntry, Result<Unit>> {
    override suspend fun execute(params: AddEntry): Result<Unit> {
        ...
        return Result.success(Unit)
    }
}

Result signature is class Result<out T> and when I try to inject Hilt throws the below error:


@Binds methods' parameter type must be assignable to the return type
    public abstract com.eeema.android.domain.usecase.UseCase<com.eeema.android.domain.model.AddEntry, kotlin.Result<kotlin.Unit>> bindAddEntryUseCase(@org.jetbrains.annotations.NotNull()

I don't know why is not possible to inject generics with in or out types. Version of Hilt: 2.43.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant