Skip to content

Allow bounded generic provides methods #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

evant
Copy link
Owner

@evant evant commented Sep 29, 2020

This allows generic construction which can be useful in some cases, ex:
retrofit.

@Compnation abstract class NetworkComponent {
    @Provides
    inline fun <reified T: Service> retrofitService(retrofit: Retrofit): T = retrofit.create<T>()
}

A type bounds other than Any is required, otherwise the provides would be
avaialble for every injection which could easily hide other errors until
runtime.

Note: reified inline provides methods only work in the ksp backend because the
method is not accesable from kapt.

evant added 2 commits October 10, 2020 16:49
This allows generic construction which can be useful in some cases, ex:
retrofit.

```kotlin
@Compnation abstract class NetworkComponent {
    @provides
    inline fun <reified T: Service> retrofitService(retrofit: Retrofit): T = retrofit.create<T>()
}
```

A type bounds other than Any is required, otherwise the provides would be
avaialble for every injection which could easily hide other errors until
runtime.

Note: reified inline provides methods only work in the ksp backend because the
method is not accesable from kapt.
@evant evant closed this Apr 16, 2021
@evant evant deleted the generic-provides branch May 4, 2025 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant