title: Static constructor in abstract class?
body: <p>Consider the following sample situation:</p>
  
  <pre><code>public abstract class Parent
  {
      private ByteBuffer buffer;
  
      /* Some default method implementations, interacting with buffer */
  
      public static Parent allocate(int len)
      {
          // I want to provide a default implementation of this -- something like:
          Parent p = new Parent();
          p.buffer = ByteBuffer.allocate(len);
          return p;
      }
  }
  
  public class Child extends Parent
  {
      /* ... */
  }
  
  public class App
  {
      public static void main(String[] args)
      {
          // I want to ultimately do something like:
          Child c = Child.allocate(10);
          // Which would create a new child with its buffer initialized.
      }
  }
  </code></pre>
  
  <p>Obviously, I can't do this (<code>new Parent()</code>) since Parent is abstract, but I don't <em>really</em> want a Parent.  I want this method to be automatically provided to subclasses.</p>
  
  <p>I would prefer to use the "static constructor" approach with <code>.allocate()</code> instead of adding another visible constructor.</p>
  
  <p>Do I have any way to put this default implementation in the <code>Parent</code> class, or must each of the subclasses contain the same code?</p>
  
  <p>I guess another option would be to strip "abstract" from the parent, but abstract fits -- I never want an object of type Parent.</p>
  
  <p>Thanks in advance.</p>