The best way to see how to use toConstructor right now would be to look at the tests in Guice. See < http://code.google.com/p/google-guice/source/browse/trunk/test/com/google/inject/BindingTest.java#221> for some examples.
The interface/class toConstructor belongs to is kind of immaterial because of the way the Guice API is written. It's just another option of how to bind something from a prior bind(..) call. FWIW, it's on the LinkedBindingBuilder interface. Javadocs don't really go well on DSL-style APIs, though. Sam On Mon, Jan 4, 2010 at 3:31 PM, JN <[email protected]> wrote: > > Could someone reply to this one? Don't know how I can be missing the > method in the javadoc. > > Thanks, > Jim > > On Dec 31 2009, 3:39 pm, JN <[email protected]> wrote: > > On Dec 31, 3:34 pm, "Dhanji R. Prasanna" <[email protected]> wrote: > > > > > Yes, you can use @Provides methods on your module or > > > > bind().toConstructor() > > > > > without any annotations at all. > > > > > > Thanks for the quick reply. Does that bind to a no-arg constructor, > > > > or how do you specify which constructor to bind to? A pointer to > docs > > > > or javadoc would be helpful. I tried to answer that question for > > > > myself, but couldn't find toConstructor() in the javadoc. I explored > > > > AbstractModule ->bind() -> to()... At this point, all I see is to(), > > > > toInstance(), toProvider(). > > > > > toConstructor() takes an argument of type Constructor<T> so you can > point it > > > to any constructor you have. You can write yourself a utility that does > > > something like: > > > > > bind(MyObject.class).toConstructor(onlyConstructorOf(MyObject.class)); > > > > > where onlyConstructorOf is a method that returns the sole constructor > in a > > > class or throws an error. > > > > Ah, that's useful to know. Still don't see it in the javadoc; is this > > 2.0 or 2.1? What's the name of the class/interface which the > > toConstructor() method belongs to? > > -- > > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
