Java 用于具有特定值的注释的Guice Multibinder
我知道我可以使用特定的注释进行Guice多绑定,如下所示Java 用于具有特定值的注释的Guice Multibinder,java,annotations,guice,Java,Annotations,Guice,我知道我可以使用特定的注释进行Guice多绑定,如下所示 Multibinder.newSetBinder(binder(), Bound.class, Annotation.class); 但是,我是否可以对不仅使用注释进行注释的类执行更具体的多重绑定。类还具有特定值,例如@Annotation(“type1”)?在这种情况下,您可以实现注释并将其实例传递给多重绑定器静态工厂方法: static class YourAnnotationImpl implements YourAnnota
Multibinder.newSetBinder(binder(), Bound.class, Annotation.class);
但是,我是否可以对不仅使用
注释进行注释的类执行更具体的多重绑定。类
还具有特定值,例如@Annotation(“type1”)
?在这种情况下,您可以实现注释并将其实例传递给多重绑定器静态工厂方法:
static class YourAnnotationImpl implements YourAnnotation {
private final String value;
YourAnnotationImpl(String value) {
this.value = value;
}
@Override public String value() {
return value;
}
@Override public Class<? extends Annotation> annotationType() {
return YourAnnotation.class;
}
@Override public String toString() {
return "@" + YourAnnotation.class.getName() + "(value=" + value + ")";
}
@Override public boolean equals(Object o) {
return o instanceof YourAnnotationImpl
&& ((YourAnnotationImpl) o).value().equals(value());
}
@Override public int hashCode() {
return (127 * "value".hashCode()) ^ value.hashCode();
}
}
...
Multibinder.newSetBinder(binder(), Bound.class, new YourAnnotationImpl("type1");
静态类YourAnnotationImpl实现YourAnnotation{
私有最终字符串值;
YourAnnotationImpl(字符串值){
这个值=值;
}
@重写公共字符串值(){
返回值;
}
@重写公共类在这种情况下,您可以实现注释并将其实例传递给Multibinder静态工厂方法:
static class YourAnnotationImpl implements YourAnnotation {
private final String value;
YourAnnotationImpl(String value) {
this.value = value;
}
@Override public String value() {
return value;
}
@Override public Class<? extends Annotation> annotationType() {
return YourAnnotation.class;
}
@Override public String toString() {
return "@" + YourAnnotation.class.getName() + "(value=" + value + ")";
}
@Override public boolean equals(Object o) {
return o instanceof YourAnnotationImpl
&& ((YourAnnotationImpl) o).value().equals(value());
}
@Override public int hashCode() {
return (127 * "value".hashCode()) ^ value.hashCode();
}
}
...
Multibinder.newSetBinder(binder(), Bound.class, new YourAnnotationImpl("type1");
静态类YourAnnotationImpl实现YourAnnotation{
私有最终字符串值;
YourAnnotationImpl(字符串值){
这个值=值;
}
@重写公共字符串值(){
返回值;
}
@重写公共类