Also posted on Stack Overflow <http://stackoverflow.com/q/8672431/403455>.
This code functions as expected:
ArrayList<Class<? extends Option>> options =
new ArrayList<Class<? extends Option>>();
bindMultibinder(annotation, options);
public Key<Set<Option>> bindMultibinder(
Named annotation, ArrayList<Class<? extends Option>> contents) {
Multibinder<Option> options =
Multibinder.newSetBinder(binder(), Option.class, annotation);
for (Class<? extends Option> option : contents) {
options.addBinding().to(option);
}
final Key<Set<Option>> multibinderKey =
Key.get(new TypeLiteral<Set<Option>>(){}, annotation);
return multibinderKey;
}
But its generic equivalent (below) does not function. Attempting to use it
results in the following error:
com.google.inject.CreationException: Guice creation errors: 1)
java.util.Set<T> cannot be used as a key; It is not fully specified.
Generic equivalent:
bindMultibinder(annotation, Option.class, options);
public <T> Key<Set<T>> bindMultibinder(
Named annotation, Class<T> superClass, ArrayList<Class<? extends T>> contents)
{
Multibinder<T> options =
Multibinder.newSetBinder(binder(), superClass, annotation);
for (Class<? extends T> t : contents) {
options.addBinding().to(t);
}
final Key<Set<T>> multibinderKey =
Key.get(new TypeLiteral<Set<T>>(){}, annotation);
return multibinderKey;
}
Guice's Key
documentation<http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/Key.html>states
only that:
Key supports generic types via subclassing just like TypeLiteral.
I need more help than that to figure out how to replace the Key<Set<T>>with
something like
Key<Set<TypeLiteral<T>>>
Thanks for any help!
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/N7baUuZY8MsJ.
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.