title: Java generics, singletons and static methods
body: <p>So I have a few 'Manager' classes, for example GroupManager. All these Managers are singletons.</p>
  
  <p>Using this method for instancing:</p>
  
  <pre><code>private static GroupManager groupManager = null;
  
  private GroupManager()
  {
  
  }
  
  public static GroupManager Instance()
  {
      if (groupManager == null)
      {
          groupManager = new GroupManager();
      }
      return groupManager;
  }
  </code></pre>
  
  <p>I'm thinking I should start to use some inheritance as they have a lot of copied methods.</p>
  
  <p>The Instance() methods for each Manager is the same.</p>
  
  <p>So for inheritance  i can do this (obviously):</p>
  
  <pre><code>GroupManager extends Manager
  </code></pre>
  
  <p>Is it possible to use generics to use the same Instance method for all managers, something like:</p>
  
  <pre><code>public class Manager&lt;E&gt;
  {
      private static E instance = null;
  
      public static E Instance()
      {
          if (instance == null)
          {
              instance = new E();
          }
          return instance;
      }
  
  }
  </code></pre>
  
  <p>I think that makes sense :)</p>
  
  <p>So then you would do GroupManager.Instance() like normal.</p>