Protostome
Protostome

Reputation: 6019

DI and generic classes in dagger

I'm trying to create a generic class from the object graph in Dagger. Taking the Coffee machine example, is there any pattern to create a generic CoffeeApp class?

CoffeeApp<String> 

for example...

Thanks!

Upvotes: 2

Views: 1348

Answers (1)

Jake Wharton
Jake Wharton

Reputation: 76075

No. Generic types can only be obtained through object injection (field or constructor) and not through get().

Your example is a bit odd because a generic CoffeeApp doesn't make much sense. You can certainly @Provide a generic type and @Inject a generic type, however.

Upvotes: 3

Related Questions