Well, I made it to the FAQ on the wiki and there is the answer, top of the
FAQ. *idiot*
I am now trying to implement my slightly complicated problem. Instead o
strings, I want the annotation to be to a class. So I have:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
@BindingAnnotation
public @interface WhisperId {
}
public class MurmurModule extends AbstractModule {
private final WhisperIdentity serverId;
public MurmurModule(WhisperIdentity serverId) {
this.serverId = serverId;
}
@Override
protected void configure() {
bindConstant().annotatedWith(WhisperId.class).to(serverId);
}
}
The call to to(...) is blowing up. It says:
Bound mismatch: The generic method to(E) of type ConstantBindingBuilder is
not applicable for the arguments (WhisperIdentity). The inferred type
WhisperIdentity is not a valid substitute for the bounded parameter <E
extends Enum<E>>
and WhisperIdentity is not an Enum.
Ok, thinking about it a bit, I need to pass in the primitive types to the
Module, build my WhisperIdentity in there and then inject that puppy. Does
that sound about right?
Thanks,
Rob
On Tuesday, October 9, 2012 4:01:28 PM UTC-4, Rob Withers wrote:
>
> I am somewhat familiar with Guice and am reading the wiki, but I have a
> question.
>
> Let's say I have a Person class, with a constructor that takes a name.
> How can I use a Guice module to create 2 instance, one with "Rob" and one
> with "Sara"? Are there different approaches? What are the implications,
> pros and cons of each approach?
>
> Thanks,
> Rob
>
--
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/-/3jR7JJkGKmIJ.
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.