Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove private from generated Factory's INSTANCE field. #4547

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

copybara-service[bot]
Copy link

Remove private from generated Factory's INSTANCE field.

Fixes #4544

Background: Dagger's generated factory has an optimization to lazy load a singleton instance of the factory when there are no dependencies:

public final class Foo_Factory implements Factory<Foo> {
  public static Foo_Factory create() {
    return InstanceHolder.INSTANCE;
  }

  private static final class InstanceHolder {
    private static final Foo_Factory INSTANCE = new Foo_Factory();
  }
}

The private modifier on the INSTANCE field is not needed and can add extra overhead as described in #4544. Removing the private modifier is also needed once we start generating Kotlin sources since accessing a private field on a nested class in kotlin source is a kotlinc error.

RELNOTES=Fixes #4544: Removes private from InstanceHolder field.

Fixes #4544

Background: Dagger's generated factory has an optimization to lazy load a singleton instance of the factory when there are no dependencies:

```
public final class Foo_Factory implements Factory<Foo> {
  public static Foo_Factory create() {
    return InstanceHolder.INSTANCE;
  }

  private static final class InstanceHolder {
    private static final Foo_Factory INSTANCE = new Foo_Factory();
  }
}
```

The `private` modifier on the `INSTANCE` field is not needed and can add extra overhead as described in #4544. Removing the `private` modifier is also needed once we start generating Kotlin sources since accessing a `private` field on a nested class in kotlin source is a kotlinc error.

RELNOTES=Fixes #4544: Removes private from InstanceHolder field.
PiperOrigin-RevId: 708101532
@copybara-service copybara-service bot merged commit 07d8f88 into master Dec 20, 2024
@copybara-service copybara-service bot deleted the test_707982073 branch December 20, 2024 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android Lint flags SyntheticAccessor for return InstanceHolder.INSTANCE statement in _Factory.java
1 participant