the official documentで、私は遅延ロードのプロバイダについての記事を読んだ。しかし、なぜこのコードの下に、遅延ロードに対応する注釈やコードが見つからないため、プロバイダを作成するのが遅れているのか理解できません。 コードはこのコードです。Guiceでの遅延ロードのプロバイダ
public class DatabaseTransactionLog implements TransactionLog {
private final Provider<Connection> connectionProvider;
@Inject
public DatabaseTransactionLog(Provider<Connection> connectionProvider) {
this.connectionProvider = connectionProvider;
}
public void logChargeResult(ChargeResult result) {
/* only write failed charges to the database */
if (!result.wasSuccessful()) {
Connection connection = connectionProvider.get();
}
}
ローディングの遅延を引き起こす特別な点はどこにありますか?
通常、依存関係が満たされると、必要なオブジェクトが作成されます。 Providersでは、 'get()'が呼び出されるまで、必要なオブジェクトは作成されません。 –