MembersInjector<B> a MembersInjector<B> and use this to enter the fields and methods of B :
class A { @Inject A(MembersInjector<B> bInjector) { ... B b = constructor.newInstance(); bInjector.injectMembers(b); b.doSomething(); } }
The best part of this approach is that Guice can prepare the bindings for B in advance. If there are problems with B injection, you will know when you create the injector that the application normally starts. This is preferable to Injector.injectMembers() , because it will not work until it is called.
source share