Can Eclipse generate method-chaining setters

Posted by Chris R on Stack Overflow See other posts from Stack Overflow or by Chris R
Published on 2009-05-22T15:37:23Z Indexed on 2010/05/16 13:20 UTC
Read the original article Hit count: 513

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.

© Stack Overflow or respective owner

Related posts about eclipse

Related posts about eclipse-plugin