我想要做的是创建地图,其中键将是扩展我的抽象类的类。
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,这将有效,但我不希望类的原始类型。如果有人能帮我解决这个问题,我会很高兴的。提前感谢
发布于 2013-11-19 11:31:59
问题解决
我为每个密钥创建了提供程序
public class KeyImplProvider implements
Provider<Class<KeyImpl>> {
@Override
public Class<KeyImpl> get() {
return KeyImpl.class;
}
}我正在添加要映射的元素
mapBinder.addBinding(KeyImplProvider.class).to(Value.class);https://stackoverflow.com/questions/19595497
复制相似问题