我刚刚按照建议尝试了 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/