2

我想做的是创建地图,其中关键将是扩展我的抽象类的类

GinMapBinder<Class<? extends Key>, Value> mapBinder = GinMapBinder
                .newMapBinder(binder(),
                        new TypeLiteral<Class<? extends Key>>() {
                        }, new TypeLiteral<Value>() {
                        });

但是当我尝试填充我的地图时

mapBinder.addBinding(KeyImpl.class).to(Value.class);

我收到错误:

 Error injecting @com.google.gwt.inject.client.multibindings.Internal() java.lang.Class<? extends my.test.gwt.gin.objects.Key>: Unable to create or inherit binding: No implementation bound   for '@com.google.gwt.inject.client.multibindings.Internal() java.lang.Class<? extendsmy.test.gwt.gin.objects.Key>' and an implicit binding cannot be created because the type is annotated.
  Path to required node:

 @com.google.gwt.inject.client.multibindings.Internal com.google.gwt.inject.client.multibindings.MapEntry<java.lang.Class<? extends my.test.gwt.gin.objects.Key>, my.test.gwt.gin.objects.Value> [com.google.gwt.inject.client.multibindings.BindingRecorder.bind(BindingRecorder.java:42)]
  -> com.google.gwt.inject.client.multibindings.MapEntry<java.lang.Class<? extends my.test.gwt.gin.objects.Key>, my.test.gwt.gin.objects.Value> [com.google.gwt.inject.client.multibindings.BindingRecorder.bind(BindingRecorder.java:42)]
  -> @com.google.gwt.inject.client.multibindings.Internal() java.lang.Class<? extends my.test.gwt.gin.objects.Key> [@Inject constructor of com.google.gwt.inject.client.multibindings.MapEntry<java.lang.Class<? extends my.test.gwt.gin.objects.Key>, my.test.gwt.gin.objects.Value>]

如果我不使用TypeLiteral它会起作用,但我不想要原始类型的类。所以如果有人可以帮助我解决这个问题,我会很高兴。提前致谢

4

1 回答 1

2

问题解决了

我为每个 Key 创建了提供程序

public class KeyImplProvider implements
        Provider<Class<KeyImpl>> {

    @Override
    public Class<KeyImpl> get() {
        return KeyImpl.class;
    }
}

我正在添加元素来映射

mapBinder.addBinding(KeyImplProvider.class).to(Value.class);
于 2013-11-19T11:31:59.957 回答