Here is an example of the issue I've come across:
public interface IFoo { ... }
public abstract class Helper implements IFoo {
public Helper() { ... }
protected abstract X helperMethod();
}
public class Foo extends Helper {
private final String aaa;
@Inject
public Foo(String aaa) { this.aaa = aaa; }
@Override
X helperMethod() { doSomethingUsingWhatsInjected(aaa); }
}
The issue is that when I bind IFoo to Foo like this:
bind(IFoo.class).to(Foo.class).in(Singleton.class);
it appears like helperMethod()
is being called before the aaa
has been Injected since I'm seeing aaa
as null
. But if I instead don't use the class Helper
and in-line all of its code directly in Foo
, guice doesn't struggle.
What's the difference between these two approaches? Why is helperMethod()
called before we know from where we're getting the implementation of IFoo
? Can we use Helper
along with injection?