I am currently exploring the possibilities of Guice and come across strange behavior - when I declare a variable as
@Inject @Named("dragon") Dragon dragon2;
the injection works as expected, but when I want to declare dragon2 as an interface (it implements the Creature), i. e.
@Inject @Named("dragon") Creature dragon2;
I get an error
There is no implementation for warlock.rincewind.creatures.Creature annotated with @com.google.inject.name.Named(value=dragon) been linked.
Here is my provider method:
@Named("dragon") @Provides public Dragon providesDragon() { Dragon d = new Dragon("Morkeleb"); return d; }
I know there are many different ways to overcome this (the simplest is changing the type of return to the Creature), but I'm trying to get the reason for this restriction.
java guice
skwisgaar
source share