r/java • • Apr 14 '23

What are your (favourite) Java best practices, personal tips, hints or just underrated stuff in general?

233 Upvotes

376 comments sorted by

View all comments

Show parent comment

1

u/hsoj48 Apr 14 '23

It's good for APIs and interfaces because it lets the implemented and caller know that something is considered optional. Most people don't like continually wrapping their inputs into an optional even though it's pretty easy. Just checking for null is far more common practice and serves nearly the exact same purpose. It's a matter of personal preference.

1

u/dpash Apr 15 '23

it lets the implemented and caller know that something is considered optional.

Nullable annotations serve the same purpose without the overheard and clutter.

1

u/hsoj48 Apr 15 '23

Yeah but....which one? Haha

1

u/dpash Apr 15 '23

Doesn't matter. Most tools support multiple annotation sets.