Understanding Dagger 2 @Component.Builder annotation : <p>I'm reading <a href="https://proandroiddev.com/dagger-2-component-builder-1f2b91237856" rel="noreferrer">this</a> great tutorial that explains how <code>@Component.Builder</code>works in Dagger 2. The author did a good job and the article is straight forward, but there still are some confusing I need to clarify: the default implementation of Dagger 2 looks something like this:</p>

<p>The component:</p>

<pre><code>@Singleton
@Component(modules = {AppModule.class})
public interface AppComponent {

  void inject(MainActivity mainActivity);
  SharedPreferences getSharedPrefs();
}
</code></pre>

<p>The module:</p>

<pre><code>@Module
 public class AppModule {

    Application application;

    public AppModule(Application application) {
       this.application = application;
    }

    @Provides
    Application providesApplication() {
       return application;
    }
    @Provides
    @Singleton
    public SharedPreferences providePreferences() {
        return application.getSharedPreferences(DATA_STORE,
                              Context.MODE_PRIVATE);
    }
}
</code></pre>

<p>Component instantiating:</p>

<pre><code>DaggerAppComponent appComponent = DaggerAppComponent.builder()
         .appModule(new AppModule(this)) //this : application 
         .build();
</code></pre>

<p>According to the article, we can simplify this code even more by avoiding passing arguments to the module constructor using <code>@Component.Builder</code> and <code>@BindsInstance</code> annotations, then the code will look like this:</p>

<p>The component:</p>

<pre><code>@Singleton
@Component(modules = {AppModule.class})
public interface AppComponent {
   void inject(MainActivity mainActivity);
   SharedPreferences getSharedPrefs();

   @Component.Builder
   interface Builder {
      AppComponent build();
      @BindsInstance Builder application(Application application);      
  }
</code></pre>

<p>}</p>

<p>The module:</p>

<pre><code>@Module
 public class AppModule {

     @Provides
     @Singleton
     public SharedPreferences providePreferences(
                                    Application application) {
         return application.getSharedPreferences(
                                    "store", Context.MODE_PRIVATE);
     }
 }
</code></pre>

<p>And the component instantiating:</p>

<pre><code>DaggerAppComponent appComponent = DaggerAppComponent.builder()
           .application(this)
           .build();
</code></pre>

<p>I almost understand how the above code works, but here is the part I don't understand: how did we get from <code>appModule(new AppModule(this))</code> to <code>application(this)</code> when we are instantiating the component?</p>

<p>I hope the question was clear and thanks.</p>
