java - 如何修复 "...PlaceHistoryMapperWithFactory cannot be implemented more than once..."

标签 java gwt

我刚刚按照建议尝试了 PlaceHistoryMapperWithFactory here 。所以我的 AppPlaceHistoryMapper 看起来像这样:

    @WithTokenizers({ InfoPlace.Tokenizer.class, LogPlace.Tokenizer.class })
public interface AppPlaceHistoryMapper extends PlaceHistoryMapperWithFactory<TokenizerFactory> {

}

我还更改了 gin 模块:

bind(PlaceHistoryMapperWithFactory.class).to(AppPlaceHistoryMapper.class);

但我不会 gwt 编译。我明白

[INFO] Compiling module de.stalabw.zensus2011.adb.AuswertungsDB
[INFO]    Scanning for additional dependencies: ...ClientInjectorImpl.java
[INFO]       Adding '57' new generated units
[INFO]          Validating newly compiled units
[INFO]             Ignored 1 unit with compilation errors in first pass.
[INFO] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[INFO]    [ERROR] Errors in '...PlaceHistoryMapperWithFactoryImpl.java'
[INFO]       [ERROR] Line 10:  The interface PlaceHistoryMapperWithFactory cannot be implemented more than once with different arguments: PlaceHistory
MapperWithFactory<Void> and PlaceHistoryMapperWithFactory
[INFO]    [ERROR] Cannot proceed due to previous errors

我刚刚在单元测试中修复了相同的错误。我有一个模拟实现。我刚刚改变了

public class PlaceHistoryMapperMock extends AbstractPlaceHistoryMapper<void> implements
AppPlaceHistoryMapper

public class PlaceHistoryMapperMock extends AbstractPlaceHistoryMapper<TokenizerFactory> implements
AppPlaceHistoryMapper

错误消失了。但如何修复我的“真实”代码?

最佳答案

问题可能是您有一个 GWT.create(PlaceHistoryMapperWithFactory.class)代码中的某处(可能由 GIN 生成),生成器尝试生成 PlaceHistoryMapperWithFactoryImpl实现 PlaceHistoryMapperWithFactory 的类(该类名是有症状的) (传递给 GWT.create() )和 PlaceHistoryMapperWithFactory<Void> (因为生成的类扩展了 AbstractPlaceHistoryMapper<Void> )。

这实际上取决于您对 PlaceHistoryMapperWithFactory 的依赖程度在您的代码中声明。

IMO,你可能应该依赖 PlaceHistoryMapper在你的代码中,而不是一些 PlaceHistoryMapperWithFactory 。如果您需要该依赖项(因为这是您调用 setFactory 的地方),您应该依赖于参数化类型 PlaceHistoryMapperWithFactory<TokenizerFactory> ,必须使用TypeLiteral映射到GIN中:

bind(new TypeLiteral<PlaceHistoryMapperWithFactory<TokenizerFactory>>() {}).to(AppPlaceHistoryMapper.class);

关于java - 如何修复 "...PlaceHistoryMapperWithFactory cannot be implemented more than once...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10535326/

相关文章:

java - PermGen 中的对象分配

java - libGDX 性能 : best time for OrthographicCamera. 更新()

java - 从 Sonar 获取 JaCoCo 集成覆盖

gwt - 什么是PP_OFF?

javascript - indexedDB 的 GWT 库

java - gwt guice 注入(inject)远程 servlet。未找到错误404

java - Scala/Java 模板列表迭代和字符串连接

java - 可扩展组件以隐藏或取消隐藏另一个组件

javascript - 是否应该避免编写 Javascript 以支持 GWT/WebSharper 或其他一些抽象?

javascript - firebug 没有显示完整的 js 文件来调试、放置 breka 点