Sorry didn't read it properly the first time.
requireBinding will only be evaluated when the injector was created successfuly. Since in your example with Integer the creation of the injector fails the requireBinding is never evaluated.

In your example the generic type T must always be of the same type as the constant (or a super type)

Am 22.08.2014 07:39 schrieb kelv...@gmail.com:
For some reason, this isn't working for me: 

public class MyModule<T> extends PrivateModule {
    private final Key<T> key;
    
    @Override
    protected void configure() {
        bindConstant().annotatedWith(key.getAnnotation()).to("42");
        requireBindings(key);
        expose(key);
    }
}

Now, if I create an injector with a MyModule<String>, things appear to be fine.  However, if I create an injector with a MyModule<Integer>, I get a creation error on the expose(), saying that it could not expose Integer with key.getAnnotation().  If I'm not mistaken, requireBindings() above seems to indicate that it is bound.

Why does this happen, and how should I resolve this? (I plan on replacing "42" with, say, System.getProperties("foobar").)

--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
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/89663f49-c0b6-4036-ab5a-5bc5e3cec494%40googlegroups.com.
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
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/0Lymoh-1WF6by47vj-016Bzm%40mail.gmx.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to