title: Design: Java and returning self-reference in setter methods
body: <p>For classes that have a long list of setters that are used frequently, I found this way very useful (although I have recently read about the <a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="noreferrer">Builder pattern</a> in <em>Effective Java</em> that is kinda the same).</p>
  <p>Basically, all setter methods return the object itself so then you can use code like this:</p>
  <pre><code>myClass
      .setInt(1)
      .setString(&quot;test&quot;)
      .setBoolean(true);
  </code></pre>
  <p>Setters simply return this in the end:</p>
  <pre><code>public MyClass setInt(int anInt) {
      // [snip]
      return this;
  }
  </code></pre>
  <p>What is your opinion? What are the pros and cons? Does this have any impact on performance?</p>
  <p>Also referred to as the <a href="http://www.cs.technion.ac.il/users/yechiel/c++-faq/named-parameter-idiom.html" rel="noreferrer">named parameter idiom</a> in c++.</p>