6

我在 Guice 中找到了 Guice Overriding Binding的答案,但不知道如何在 GWT 中为 GIN 做同样的事情。

提前致谢!

4

2 回答 2

5

据我所知,不支持。

要回答您的评论:

如果您正在运行“纯”JUnit 测试(不是 GWTTestcases),那么您不使用 GIN,而是使用 Guice,并且在 Guice 中您可以覆盖模块。如果要重用 GIN 模块,请使用GinModuleAdapter. 所以你可以做这样的事情:

static class MyGinModule extends GinModule {
  ...
}
static class MyGuiceModule extends AbstractModule {
  ...
}

// And somewhere in your code, here's how you could create the Injector
Module myWrappedGinModule = new GinModuleAdapter(new MyGinModule());
Module myModule = Modules.override(myWrappedGinModule).with(new MyGuiceModule());
Injector injector = Guice.createInjector(myModule);
于 2011-09-06T03:42:16.080 回答
0

在您的界面中使用@ImplementedBy注释。

注释中指定的类将是默认实现。

您可以指定另一个实现,有效地覆盖默认值。

例如:

@ImplementedBy(MyWidgetImpl.class)
public interface MyWidget {
  //...
}

public class MyWidgetImpl implements MyWidget {
  //...
}
于 2011-11-15T00:20:10.550 回答