title: Dagger 2 - what is the purpose of a @Singleton annotation class
body: <p>From the dagger 2 <a href="http://google.github.io/dagger/" rel="noreferrer">Documentation</a> I noticed that you can have a <code>@Singleton</code> annotated class. What is the purpose of marking a class as <code>@Singleton</code> as I have tried to do this in my code but a singleton object is NOT produced. I'm not clear on what use marking my class with this annotation serves.  </p>
  
  <p>From the documentation please focus on the following statement:</p>
  
  <blockquote>
    <p>The @Singleton annotation on an injectable class also serves as
    documentation. It reminds potential maintainers that this class may be
    shared by multiple threads.*</p>
  </blockquote>
  
  <pre class="lang-java prettyprint-override"><code>@Singleton
  class CoffeeMaker {
      // ...
  }
  </code></pre>
  
  <p>UPDATE: After reviewing froger_mcs answer I see that in Dagger 2 you can provide injections either by a module OR by a constructor injection. So the following class, although not in a module, can be injected:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Singleton
  public class MyClass {
      @Inject
      public MyClass() {
  
      }
  }
  </code></pre>
  
  <p>In this version the constructor is injected for us and in an Android activity you would just do the following and it will get provided:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Inject
  MyClass myClass;
  //then in onCreate actually inject(this) from your graph of course.
  </code></pre>