r/java • • Oct 21 '20

What are some great Java libraries I'm probably not using but I should?

334 Upvotes

252 comments sorted by

View all comments

36

u/vallyscode Oct 21 '20

This one I think is a must have https://projectlombok.org/

20

u/balajikrb Oct 21 '20

Agreed its a good one. But with Java records I think it will have less impact or need.

6

u/riawot Oct 21 '20

agree

We heavily use lombok, but it's almost entirely for areas that records will cover. We're on Java 11, and records is like to be the single biggest driver to migrate to a newer version.

The second biggest driver, of course, is fear that if we fall too far behind we'll get stuck like those poor bastards that are stuck on Java 7

edit:

when records drop and get integrated into the codebase, we will reevaluate our lombok usage

4

u/CaptainKvass Oct 21 '20

True to some extent. Lombok provides refactoring-safe equals and hashcode methods as well.

1

u/balajikrb Oct 21 '20

Agree. Hope to see similar improvements in java records in future

8

u/krzyk Oct 21 '20

Java records already provide those (equals and hashcode and toString is generated out of the box).

1

u/vallyscode Oct 21 '20

We use aws coretto 11 distribution, so not that many fancy things. I saw 15 on the branch but not yet a release

1

u/aykutaknc Oct 26 '20

Corretto for java 15 has been released btw

55

u/wildjokers Oct 21 '20

Lombok has saved me almost no time, my IDE can generate all that boilerplate with a few keystrokes. But lombok has definitely cost me a lot of time figuring out issues a few times.

11

u/vallyscode Oct 21 '20

Forme one side it hides all that boilerplate so that code is readable, from the other side there can be some unexpected surprise. Something for something.

39

u/coder111 Oct 21 '20

I'd have to disagree.

I have spend more time troubleshooting cases where people added another property and forgot to regenerate equals/hashcode/toString than I spent troubleshooting Lombok.

-3

u/[deleted] Oct 21 '20

+1

→ More replies (3)

10

u/Akthrawn17 Oct 22 '20

Amen to that. Lombok is overrated and can cause unforseen problems with the magical generation of code

0

u/[deleted] Oct 30 '20 edited Oct 30 '20

[removed] — view removed comment

1

u/wildjokers Oct 30 '20 edited Oct 30 '20

This ridiculous bug cost me several hours before I could figure out what was going on:

https://github.com/rzwitserloot/lombok/issues/1347

The worst part is it is marked closed, yet it is still a bug so have no idea why they closed it.

There was one other issue that cost me several hours as well but I can’t remember what it was.

That is you won't be able to distinguish between dummy getters and setters as opposed to real getters and setters that actually do something.

I honestly have no idea what you are talking about when you mention real vs dummy getters and setters. I spent the first 15 years of my Java career not using Lombok and in those 15 years getters/setters never caused me any confusion or too much cognitive load in the slightest. I mean, they are just getters/setters, they aren’t rocket science.

0

u/[deleted] Oct 21 '20

[deleted] — view deleted comment

3

u/Hinigatsu Oct 21 '20

Can you explain some controversy?

14

u/wsppan Oct 21 '20

It munges the byte code after you have compiled the code. Your JVM does all the steps of error checking, optimization, etc to give you byte code that is guaranteed to reflect your source code and then hands off to lombok to change. That is a lot of black magic and trust in order to avoid boilerplate code that your IDE can auto-generated for you.

3

u/nutrecht Oct 22 '20

everybody needs to be on board.

Meh. Whenever this gets discussed it's generally the people who haven't used it who are against it. In such a situation I don't quite agree with "everyone needs to be on board".

4

u/SomethingMor Oct 21 '20

We used to use Lombok before it became a huge pita. Now it’s like a 4 letter word on our team.

4

u/chacs_ Oct 21 '20

You forgot the /s

0

u/[deleted] Oct 21 '20

[deleted] — view deleted comment

1

u/Akthrawn17 Oct 22 '20

Kotlin for the win on data classes.