How can I abstract the Option type in the below Guice binding code, substituting a generic parameter for Option?
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;
}
Thanks to Stuart McCulloch on Google Groups for answering:
To get this to build correctly, I modified it as follows:
So the complete generic method is: