Skip to content

Scoped generic class fails to build #671

@bubenheimer

Description

@bubenheimer

The following fails to build:

@Component
interface FooComp {
    Foo<Integer> foo();
}

@Reusable
class Foo<T> {
    @Inject
    Foo() {}
}

Error:(26, 44) error: incompatible types: Provider<Foo<Object>> cannot be converted to Provider<Foo<Integer>>

However, when adding another @Inject element or removing scoping it succeeds:

@Reusable
class Foo<T> {
    @Inject
    Foo() {}

    @Inject
    void postConstruct() {}
}

The problem in the first case is that Dagger is overeager to use a single static factory instance for generating instances of scoped generic classes.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions