The "many to one binding" thing isn't really the reason since it's not a binding, it's just a method call in your factory.
For assistedinject, the lack of being able to specify <T> on the method w/o also specifying it on the factory is really just a no one's had the time to sit down and figure out how to do it. See the bug @ https://github.com/google/guice/issues/218 . Implementation's @ https://github.com/google/guice/blob/master/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider2.java if you want to give it a go. sam On Tue, May 26, 2015 at 6:08 PM Nate Bauernfeind <[email protected]> wrote: > Assuming you meant: > interface FooFactory { > <T> Foo<T> create(T bar); > } > > No, this does not work. It would require one-to-many bindings, which, if > you read the recent forum's history, is not supported. > > This is the closest you can get. I use it pretty frequently: > interface FooFactory<T> { > Foo<T> create(T bar); > } > > You will need to use type literals to capture the generic types when you > create the assisted inject factories. (See: > http://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/TypeLiteral.html > ) > > Nate > > On Tue, May 26, 2015 at 5:52 PM Brad Micholson <[email protected]> > wrote: > >> Is there currently any way to use type inference in an assisted inject >> factory? >> For example, is there any way to use an interface like the following as >> an assisted inject factory? >> >> >> interface FooFactory >> { >> Foo<T> create(T bar); >> } >> >> -- >> 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 post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/google-guice. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/google-guice/3b354f12-1927-44fb-ac0d-94b28941ced6%40googlegroups.com >> <https://groups.google.com/d/msgid/google-guice/3b354f12-1927-44fb-ac0d-94b28941ced6%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- > 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 post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/google-guice. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-guice/CAHNex995t_ae%2BKnFpHSxB5vVHLNkP%2BhY%2BdCt5-8VQOpM1BsHqw%40mail.gmail.com > <https://groups.google.com/d/msgid/google-guice/CAHNex995t_ae%2BKnFpHSxB5vVHLNkP%2BhY%2BdCt5-8VQOpM1BsHqw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CAJEBNUdoCzATtdVH2zBS%2BZgdjQYUCWbq9gn2xh-AvfzEwkB6Dg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
