通用 Guice 模块
在 Guice 3 中,我试图创建一个通用模块:
public class CSVModule<K> extends AbstractModule implements Serializable {
public List<Range<K>> searchRange = new LinkedList<Range<K>>();
@Override protected void configure() {
bind(new TypeLiteral<List<Range<K>>>(){}).toInstance(searchRange);
}
}
这会导致异常:
1) java.util.List<test.Range<K>> cannot be used as a key; It is not fully specified.
searchRange 应该从“外部”配置:
module = new CSVModule<Integer>();
module.searchRange.add(new Range<Integer>(-5, 5));
但是,我不仅有整数搜索范围,所以我想避免对 CSV 进行子类化适用于每种类型的模块。
如果有人能帮忙的话那就太好了。
In Guice 3, I am trying to create a generic Module:
public class CSVModule<K> extends AbstractModule implements Serializable {
public List<Range<K>> searchRange = new LinkedList<Range<K>>();
@Override protected void configure() {
bind(new TypeLiteral<List<Range<K>>>(){}).toInstance(searchRange);
}
}
This results in the exception:
1) java.util.List<test.Range<K>> cannot be used as a key; It is not fully specified.
The searchRange is supposed to be configured from the "outside":
module = new CSVModule<Integer>();
module.searchRange.add(new Range<Integer>(-5, 5));
However, I have not only Integer search Ranges so I would like to avoid subclassing the CSV Module for every type.
Would be awesome if anyone can help with that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论