views:

314

answers:

3

I'd like to generate method-chaining setters (setters that return the object being set), like so:

public MyObject setField (Object value) {
    this.field = value;
    return this;
}

This makes it easier to do one-liner instantiations, which I find easier to read:

myMethod (new MyObject ().setField (someValue).setOtherField (someOtherValue));

Can Eclipse's templates be modified to do this? I've changed the content to include return this; but the signature is not changed.

+1  A: 

Don't use eclipse myself, but you'll have to change one of the standard templates if you can't find a feature.

It's called method chaining by the way (which might help with a Google search or two).

atc
Thanks, I've amended the question to explicitly state that.
Chris R
+3  A: 
VonC
I was pretty sure that it wouldn't be core functionality. Any idea about a plugin that does it?
Chris R