Suppose I have the following base class, Queen and Knight as its derivatives. WeaponBehaviour is an interface. I can’t figure out how to inject weapons using Guice depending on the concrete GameCharacter type.
public abstract class GameCharacter {
@Inject
protected WeaponBehaviour weapon;
public GameCharacter() {
}
public void fight() {
weapon.useWeapon();
}
public void setWeapon(WeaponBehaviour weapon) {
this.weapon = weapon;
}
}
You could use Binding Annotations.
A subclass:
The Annotation:
The Binding: