Lombok: Vararg for setters / builder

Created on 20 Jan 2017  Â·  2Comments  Â·  Source: projectlombok/lombok

Idea: For arrays Builder and Setters may generate a vararg parameter.

Example

@Setter
class NameContainer {
  private String[] names;
}

will generate:

class NameContainer {
  private String[] names;
  public setNames(String... _names) {
    this.names = _names;
  }
}

This feature would also be nice for Builders.

Maybe related to #932.

Most helpful comment

Thanks for your evaluation. Answer accepted. I like varargs because it's a very simple way of passing many elements. Code can still be kept small without this feature by using List<T> and static import of Arrays.asList(...).

All 2 comments

@rspilker and I talked about it; feature request denied.

Arrays are like low-level assembler. The whole point of the varargs concept is to make nice API, and arrays fundamentally clash with the notion of nice API. We'd be writing a cheque our code couldn't cash – creating the impression this is supposed to be nice API without actually having it. Sending mixed messages.

The proper way to do this is with @Builder.

Thanks for your evaluation. Answer accepted. I like varargs because it's a very simple way of passing many elements. Code can still be kept small without this feature by using List<T> and static import of Arrays.asList(...).

Was this page helpful?
0 / 5 - 0 ratings