r/java • • Jun 01 '24

What java technology (library, framework, feature) would not recommend and why?

165 Upvotes

464 comments sorted by

View all comments

1

u/DelayLucky Jun 02 '24 edited Jun 02 '24

Another funny idiom:

Profile createProfile(String id, Date birthday, Gender gender, String firstName, String lastName) {
  return Profile.builder()
      .setId(id)
      .setBirthday(birthday)
      .setGender(gender)
      .setFirstName(firstName)
      .setLastName(lastName)
      .build();
}

Comment: how much do you hate the builder pattern? The frameworks spent so much effort to build these nice builder features so you can chain, and you can pass the parameters by name, and avoid passing them in the wrong order etc. only for you to go through the trouble to undo all that using a factory method with many parameters so that you could live in the days before the builder pattern was born.

Sometimes the love of "one-liner" in the literal sense is overwhelming.

2

u/account312 Jun 03 '24

That's a perfectly reasonable function. It guarantees that a specific set of fields are provided to the builder.

→ More replies (3)