title: Java init method
body: <p>What's a good way to make sure an init method is invoked in java? The alternatives I see are</p>
  
  <ul>
  <li>Don't test it, let the method fail by itself, likely by a <code>NullPointerException</code></li>
  <li>Test if method was initialized or throw</li>
  </ul>
  
  
  
  <pre><code>public void foo() {
       if (!inited) {
           throw new IllegalArgumentException("not initalized");
       }
       ...
  }
  </code></pre>
  
  <ul>
  <li>Delagate</li>
  </ul>
  
  
  
  <pre><code>public void foo() {
       if (!inited) {
           throw new IllegalArgumentException("not initalized");
       }
       fooInternal();
  }
  
  private void fooInternal(){ ... };
  </code></pre>
  
  <ul>
  <li>Always init, and make init a noop otherwise</li>
  </ul>
  
  
  
  <pre><code>public void foo() {
       init();
       ...
  }
  public void init() {
       if(!inited) {
           ...
       }
  }
  </code></pre>
  
  <ul>
  <li>Silently init</li>
  </ul>
  
  
  
  <pre><code>public void foo() {
       if (!inited) {
           init();
       }
       ...
  }
  </code></pre>
  
  <p>Most of these approaches are very verbose and decreases overall readability. </p>