title: When should I return the current instance as opposed to void?
body: <p>Consider this scenario:</p>
  
  <pre><code>public void setInt(int i){
      this.i = i;
  }
  </code></pre>
  
  <p>versus:</p>
  
  <pre><code>public MyClass setInt(int i) {
      this.i = i;
      return this;
  }
  </code></pre>
  
  <p>Consider if you want to print the internal integer.  If we use <code>void</code> as a return value to <code>setInt</code>, we use this code:</p>
  
  <pre><code>MyClass m = new Class();
  m.setInt(10);
  System.out.println(m.getInt());
  </code></pre>
  
  <p>If we use <code>MyClass</code> as the return value to <code>setInt</code>, we use this code:</p>
  
  <pre><code>System.out.println(new MyClass().setInt(10).getInt());
  </code></pre>
  
  <p>To me, the second approach seems cleaner and tidier, but I've still got a question about these approaches.</p>
  
  <ul>
  <li>In what circumstances would the first approach (using <code>void</code>) be OK to use? </li>
  <li>In what circumstances would the second approach be OK to use?</li>
  </ul>