@注入guice模块

时间:2019-02-20 03:37:26

标签: guice

在模块类中,我们是否需要@Inject overprovids___方法? 例如。

    @Singleton
    @Provides
    @Inject
    A provideA(ExampleClass1<B> example1, ExampleClass2 example2) {
        return new A(example1, example2);
    }

    @Provides
    @Singleton
    @Inject
    B provideB(A a) {
        return new B(new C(a));
    }

在此示例中,我需要@Inject吗?

1 个答案:

答案 0 :(得分:1)

不。 @Provides方法不需要@Inject批注。 @Provides方法的参数已经自动注入。

相关问题