when I run the code below, I get the output "Bar got 1234".
it looks like Guice can't find a binding for num2, and implicitly assigns
the value of num1.
Is this part of the AssistedInject feature? I couldn't find any mention of
this in the wiki.
changing num2's type to float throws this exception (as I'd expected):
"No implementation for java.lang.Float annotated with
@com.google.inject.assistedinject.Assisted(value=) was bound."
class Foo {
@Inject
public Foo(@Assisted final int num1, final Bar bar) { } interface
FooFactory {
Foo create(final int num1);
}
}class Bar {
@Inject
public Bar(@Assisted final int num2) {
System.out.println("Bar got "+num2);
}
}class BillingModule extends AbstractModule {
@Override
protected void configure() {
install(new FactoryModuleBuilder()
.implement(Foo.class, Foo.class)
.build(Foo.FooFactory.class));
}
}public class App
{
public static void main( String[] args ) {
Injector injector = Guice.createInjector(new BillingModule());
Foo.FooFactory fooFactory = injector.getInstance(Foo.FooFactory.class);
fooFactory.create(1234);
}
}
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/c9c29e41-04a4-4330-9066-3aa4cfc5ac58%40googlegroups.com.