Android Dagger 2: Inject versus Provides
<p>I have a question regarding Android Dagger 2 und the usage of <code>@Inject</code> and <code>@Provide</code> annotations. Given are the following two simplified examples:</p>

<pre><code>public class A {
  String msg;

  public A(String msg){
    this.msg = msg;
  }
}

public class B {
  public A a;

  public B(A a){
    this.a = a;
  }
}

@Module
public class AModule {
  @Provides
  A providesA(){
    return new A("blah");
  }

  @Provides
  B ProvidesB(A a)
  {
    return new B(a);
  }
}
</code></pre>

<p>The example is pretty straight forward, I have two methods in my <code>AModule</code> with <code>@Provides</code> annotations. Therefore, Dagger can create an object of <code>B</code> using an instance of <code>A</code> with the string <code>blah</code>.</p>

<p>My second example looks like this:</p>

<pre><code>public class A {
  String msg;

  public A(String msg){
    this.msg = msg;
  }
}

public class B {
  public A a;

  @Inject
  public B(A a){
    this.a = a;
  }
}

@Module
public class AModule {
  @Provides
  A providesA(){
    return new A("blah");
  }
}
</code></pre>

<p>In this example, Dagger can create an instance of <code>B</code> because an object <code>A</code> can be created using <code>AModule</code>. The instance of <code>B</code> can be created because it's constructor uses the <code>@Inject</code> annotation.</p>

<p>So my question is: What's the difference between those two examples? Both seem to have the same semantics. Does the generated code differ and are there any pitfalls? Or is it just a matter or personal taste or best practices?</p>