title: Is it bad practice to make a setter return "this"?
body: <p>Is it a good or bad idea to make setters in java return "this"?</p>
  
  <pre><code>public Employee setName(String name){
     this.name = name;
     return this;
  }
  </code></pre>
  
  <p>This pattern can be useful because then you can chain setters like this:</p>
  
  <pre><code>list.add(new Employee().setName("Jack Sparrow").setId(1).setFoo("bacon!"));
  </code></pre>
  
  <p>instead of this:</p>
  
  <pre><code>Employee e = new Employee();
  e.setName("Jack Sparrow");
  ...and so on...
  list.add(e);
  </code></pre>
  
  <p>...but it sort of goes against standard convention. I suppose it might be worthwhile just because it can make that setter do something else useful. I've seen this pattern used some places (e.g. JMock, JPA), but it seems uncommon, and only generally used for very well defined APIs where this pattern is used everywhere.</p>
  
  <p>Update:</p>
  
  <p>What I've described is obviously valid, but what I am really looking for is some thoughts on whether this is generally acceptable, and if there are any pitfalls or related best practices. I know about the Builder pattern but it is a little more involved then what I am describing - as Josh Bloch describes it there is an associated static Builder class for object creation.</p>