@inject in guice模块

问题描述 投票:0回答:1

我们是否需要@Inject而不是模块类中的provide___方法?例如。

    @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吗?

guice
1个回答
1
投票

没有.@Provides方法不需要@Inject注释。 @Provides方法的参数已经自动注入。

© www.soinside.com 2019 - 2024. All rights reserved.