I have started using a technique, adopted from jQuery, called chaining in my setters. Example:
class Foo {
private int bar;
private int baz;
public int getBar() { return this.bar; }
public int getBaz() { return this.baz; }
public Foo setBar(int bar) {
this.bar = bar;
return this;
}
public Foo setBaz(int baz) {
this.baz = baz;
return this;
}
}
I prefer this way, because it makes easy to set multiple properties very easily.
Is there a drawback? I have asked several Java programmers about this, but all they could say is that it is "not nice", but they couldn't give me a proper explanation why.