Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用于具有特定值的注释的Guice Multibinder_Java_Annotations_Guice - Fatal编程技术网

Java 用于具有特定值的注释的Guice Multibinder

Java 用于具有特定值的注释的Guice Multibinder,java,annotations,guice,Java,Annotations,Guice,我知道我可以使用特定的注释进行Guice多绑定,如下所示 Multibinder.newSetBinder(binder(), Bound.class, Annotation.class); 但是,我是否可以对不仅使用注释进行注释的类执行更具体的多重绑定。类还具有特定值,例如@Annotation(“type1”)?在这种情况下,您可以实现注释并将其实例传递给多重绑定器静态工厂方法: static class YourAnnotationImpl implements YourAnnota

我知道我可以使用特定的注释进行Guice多绑定,如下所示

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(字符串值){
这个值=值;
}
@重写公共字符串值(){
返回值;
}
@重写公共类