I have already proposed this in my blog, but I find this place the most appropriate.
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 Builder pattern in Effective Java that is kinda the same). Basically, all setter methods return the object itself so then you can use code like this:
MyClass
.setInt(1)
.setString("test")
.setBoolean(true)
;
Setters simply return this in the end:
public MyClass setInt(int anInt) {
[snip]
return this;
}
What is your opinion? What are the pros and cons? Does this have any impact on performance?