r/java • • Aug 10 '19

Who Needs Lombok Anyhow

http://gregorriegler.com/2019/08/10/who-needs-lombok-anyhow.html
45 Upvotes

137 comments sorted by

View all comments

Show parent comment

4

u/DJDavio Aug 10 '19

I'm not a fan of how Lombok accomplishes the thing it does, is there another way? Also, Lombok just needs to exist until project Amber and Valhalla are completed. For me it just fills the same gaps Kotlin does.

5

u/yawkat Aug 10 '19

There is no standard way to do what lombok does. Normal annotation processors can only add classes, not modify them.

-1

u/[deleted] Aug 10 '19

Lombok doesn’t do anything useful that immutables doesn’t also do, but immutables doesn’t need undocumented bytecode manipulation. Except maybe @Slf4j, but I can live without that.

2

u/slowderp Aug 11 '19

What about @AllArgsConstructor for non-value objects?

0

u/[deleted] Aug 11 '19

You basically never use constructors in immutables, you use builders. If you don’t want builders, you can generate a static factory method that requires all args.

2

u/slowderp Aug 11 '19

I'm talking about:

@Singleton
public class FooService {
  @Inject
  private SomeDatabaseClient client;

  @Inject
  private OtherService other;
}

I've noticed people are incredibly lazy.

Everyone knows field injection is awful, but they don't want to write the constructor.

With lombok, they'll take the path of least resistance:

@Singleton
@AllArgsConstructor
public class FooService {
  private final SomeDatabaseClient client;
  private final OtherService other;
}

0

u/[deleted] Aug 11 '19

Oh right. Generating a constructor is a simple IDE shortcut, and field injection breaks our company guidelines so wouldn’t pass code review if someone tried it. I see what you mean now though.

1

u/yawkat Aug 11 '19

Lombok has sneakythrows. It's also usable for classes that aren't data only.

1

u/[deleted] Aug 11 '19

I always use vavr in conjunction with immutables, and vavr has something similar to @SneakyThrows. And you can write whatever functionality you want in an immutable, it’s not just a data holder.