title: Require that the same thing be done at the beginning of every override of abstract method
body: <p>I have an abstract class with an abstract method that I want subclasses to override. I need to ensure that every override of this method has the same specific line of code at the start, i.e. like this:</p>
  
  <pre><code>abstract void method();
  </code></pre>
  
  <p>and later</p>
  
  <pre><code>@Override
  void method() {
      // mandatory line of code
  
      // do stuff here
  }
  </code></pre>
  
  <p>I don't like this naive approach, since it isn't a hard requirement, i.e. an override can theoretically be made without that line. I was also thinking of doing this:</p>
  
  <pre><code>public void wrapper() {
      // mandatory line of code goes here
  
      method();
  }
  
  abstract void method();
  </code></pre>
  
  <p>I also don't like this, since I will only want to call <code>wrapper()</code> from the outside, and not <code>method()</code>, so it would make sense for <code>method</code> to be private, and yet it is public by default (since it is abstract). Is there a neater way? Or should I just make it a precondition that you must include the mandatory line of code, otherwise you get undefined behaviour?</p>