java - Dagger 错误:“@AssistedFactory 注释类型应包含一个抽象的非默认方法,但发现有多个”
问题描述
我正在学习使用Dagger和辅助注入,并且我有以下工厂界面
@AssistedFactory
public interface IFactory{
HandlerA createHandlerA (String path);
HandlerB createHandlerB (String path);
HandlerC createHandlerC (String path);
HandlerD createHandlerD (String path);
}
当我尝试编译时,我收到一条消息:
The @AssistedFactory-annotated type should contain a single abstract, non-default method but found multiple
API 文档说了同样的话,但我真的不明白它的含义,并且非常感谢任何解释,以及建议以及将来如何修复/避免它。谢谢!
解决方案
它说你想要
@AssistedFactory
public interface IFactoryA {
HandlerA createHandlerA (String path);
}
@AssistedFactory
public interface IFactoryB {
HandlerB createHandlerB (String path);
}
@AssistedFactory
public interface IFactoryC {
HandlerC createHandlerC (String path);
}
@AssistedFactory
public interface IFactoryD {
HandlerD createHandlerD (String path);
}