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").)