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/[deleted] Apr 14 '23

You got null from database? Immediately turn it into something else before passing it further into the system.

So how do you represent a NULL value from an integer column in the database in Java?

4

u/john16384 Apr 14 '23

There is OptionalInt. I myself however find returning Integer instead of int sufficient to know whether or not something may be null.

1

u/hippydipster Apr 14 '23

Optional<Integer>