bindConstant() and Private modules

11 views
Skip to first unread message

kel...@gmail.com

unread,
Aug 22, 2014, 1:39:21 AM8/22/14
to google...@googlegroups.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").)
Reply all
Reply to author
Forward
0 new messages