-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support extending base builder classes #2574
Comments
I think you need to write it like this, which is a little gross but covers everything interface BaseComponent {
fun builder(): Builder
interface Builder<T : BaseComponent, B : Builder<T, B> {
@BindsInstance fun charSequence(sequence: CharSequence): B
fun build(): T
}
}
@Subcomponent
interface SomeComponent : BaseComponent {
override fun builder(): SomeComponent.Builder
@Subcomponent.Builder
interface Builder : BaseComponent.Builder<SomeComponent, Builder>
} |
More testing and it turns out my issue was something else. First issue, I used @Component
interface ParentComponent {
public fun builder(): MySubcomponent.Builder
} I changed it to The second problem was that I had this method in my Builder class @BindsInstance public fun int(int: Int): Builder This seems to trigger an error in Dagger and it'll complain about a missing binding. Changing the method name to anything else like After making these changes my initial sample works: @Component
public interface TestAbcComponent {
public fun createBuilder(): SomeComponent.Builder
}
public interface BaseComponent {
public interface Builder {
@BindsInstance public fun charSequence(sequence: CharSequence): Builder
public fun build(): BaseComponent
}
}
@Subcomponent
public interface SomeComponent : BaseComponent {
@Subcomponent.Builder
public interface Builder : BaseComponent.Builder {
@BindsInstance override fun charSequence(sequence: CharSequence): SomeComponent.Builder
override fun build(): SomeComponent
}
} |
Yep, the Dagger component always has a static
I tested this, and the issue is that kapt will just skip the |
That makes sense, thanks for taking a quick look. The title of this issue is now a little confusing. Do you want me to create new tickets for these two issues or do you have it covered now? |
Separate issues sounds great, if you don't mind. Thanks! |
This example for factories compiles fine:
Notice how I override all the base classes to the concrete types.
Changing the Factory to a Builder doesn't work and I don't see a reason why Dagger shouldn't support it:
Dagger throws several different errors depending on other changes. The first I run into is:
After stopping to rely on the binding I see this error:
The text was updated successfully, but these errors were encountered: