title: How can I have a Singleton that's derived from an abstract base type in Java?
body: <p>I have some classes that are used as Singletons. They share some basic functionality and extend the same ancestor from a library which in turn isn't normally used as a Singleton.</p>
  
  <p>If I put the common functionality in a base class that inherits from the common ancestor, I get a class which makes no sense to instantiate, so I made it abstract. Also, because the classes are all used as Singletons, they should all have an init() and a getInstance() method, which are both static. All the constructors are of course non-public.</p>
  
  <p>Now, since <code>static</code> is an illegal modifier for abstract methods, the following doesn't work, although this would be exactly what I want:</p>
  
  <pre><code>class Base extends LibraryClass {
      protected Base() {
          // ... constructor
      }
  
      // ... common methods
  
      // ILLEGAL!
      public static abstract void init();
      public static abstract &lt;T extends Base&gt;T getInstance();
  }
  
  class A extends Base {
      private static A _INSTANCE;
  
      private A() {
          super();
      }
  
      public static void init() {
          _INSTANCE = new A();
      }
  
      public static A getInstance() {
          return _INSTANCE;
      }
  }
  </code></pre>
  
  <p>I could just leave out the illegal lines in the base class and be done with it. But how do I express that every child of Base <em>must</em> have these methods?</p>