To avoid calling get()
which can throw an exception:
if (a.isPresent())
list.add(a.get());
I can replace this expression with:
a.ifPresent(list::add);
But what if I need to perform a larger expression like:
if (a.isPresent() && b && c)
list.add(a.get());
Is it possible to still use a lambda form for this that mitigates a call to get()
?
My use-case is to avoid get()
entirely where possible to prevent a possible unchecked exception being missed.