有什么方法可以检查接口(interface)是否存在实现吗?
例如,下面的方法“hasBind”不存在:
public class MyModule extends AbstractModule {
@Override
protected void configure() {
// do something like this:
if (!hasBind(SomeInterface.class)) {
bind(SomeInterface.class).to(MyOtherSomeInterface.class);
}
}
}
最佳答案
由于应用模块的顺序在 guice 中并不重要,因此您无法检测创建注入(inject)器之前是否存在绑定(bind),请参阅 this post .
建议的解决方案是创建一个具有默认绑定(bind)的启动模块,并使用 Modules.overwrite
来应用额外的绑定(bind)。
关于java - Guice Binder 具有Bind 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37092065/