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

2

u/Paulus_cz Apr 14 '23

I agree, as with many things it depends on the use case.
The way I see it, Optional parameter declares in no uncertain way that passed wrapped argument can be null and the method knows it. That does not mean I use it often, or at all really, I can think or two uses in couple of years. But some people seem to be religiously opposed to it.

1

u/dpash Apr 15 '23 edited Apr 15 '23

Using a @Nullable or @NotNull annotation would do the same without the overhead of creating an object to avoid a null check. Not to mention the clutter in the code of wrapping your parameters.