title: Java - Force subclasses to call super method after constructor
body: <p>I want a bunch of subclasses to call a super method after finishing the constructor like this:</p>
  
  <pre><code>public abstract class Superclass {
  
      ...
  
      public Superclass(...) {
          ...    // do stuff before initializing subclass
      }
  
      protected void dispatch() {     //method to be called directly after creating an object
          doStuff();
          ...
      }
  
      public abstract void doStuff();
  }
  
  public class Subclass extends Superclass {
  
      ...
  
      public Subclass(...) {
          super(...);     //has to be the first line
          ...             //assign variables etc.
          dispatch();     //has to be called after variables are assigned etc.
      }
  
      public void doStuff() {
          //do stuff with assigned variables etc.
      }
  }
  </code></pre>
  
  <p>The <code>dispatch()</code> function contains a set of things to do with the object after it has been created, which has to apply to all subclasses. I can't move this function into the super constructor, since it calls methods from the subclasses which require already assigned variables. But since <code>super()</code> requires to be the first line of the sub constructor though, I can't set any variables until after the super constructor was called.</p>
  
  <p>It would work as it is now, but I find it a bad concept to call <code>dispatch()</code> at the end of every subclasses' constructor. Is there a more elegant way to solve this? Or should I even completely rethink my concept?</p>