Hi Fred,
I tried my best to follow the documentation provided on Annotation
when defining the implementation for my custom annotation. Here is
the class that I created. Hopefully you can spot something I missed.
For testing I have used a String value instead of Enum that I
eventually wish to use (if I ever get this to work). The annotation
has only one field.
public class RegistrarImpl implements Registrar{
public String theValue;
public RegistrarImpl(String value){
theValue = value;
}
public String value(){
return theValue;
}
public Class<? extends Annotation> annotationType() {
return Registrar.class;
}
public boolean equal(Object obj){
if (obj instanceof Registrar){
return theValue.equals(
((Registrar)obj).value());
}
return false;
}
public int hashCode(){
return value().hashCode();
}
}
It is quite strpublic class RegistrarImpl implements Registrar{
public String theValue;
public RegistrarImpl(String value){
theValue = value;
}
public String value(){
return theValue;
}
public Class<? extends Annotation> annotationType() {
return Registrar.class;
}
public boolean equal(Object obj){
if (obj instanceof Registrar){
return theValue.equals(
((Registrar)obj).value());
}
return false;
}
public int hashCode(){
return value().hashCode();
}
}
I find it quite strange that passing the class Registrar.class as the
fourth parameter to the newBinder method matches it to the annotation
with the value provided.
@Inject(optional=true)
public void registerAll (@Registrar ("100") Map<String, Object> aMap)
{
theMap.putAll(aMap);
}
It is almost like Guice is ignoring the value provided with the
annotation when creating the MapBinder.
Thanks,
GuptaJi