5
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 16 Jun 2023
5 points (100.0% liked)
Java
1395 readers
1 users here now
For discussing Java, the JVM, languages that run on the JVM, and other related technologies.
founded 1 year ago
MODERATORS
Instead of wrapping it in an optional you can do
Objects.requireNonNullElse(value, defaultValue)
Optional has more syntactic sugar for more complex scenarios / functional call chaining that prevents repetitive
if
checksThis is completely null safe, the function calls are only made if the object is not null