-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Currently `java.util.Optional` has ifPresent() method if we want to do something if the value is present.
Whereas if we want to do something "only" when the value is absent (empty), we are forced to use Optional.ifPresentOrElse().
In this case, we are forced to write an empty consumer / lambda (stale code) in ifPresent part like following
Optional.ifPresentOrElse(unused -> {}, doSomethingWhenEmpty());
Or use an if condition like following which is not so expressive
if (Optional.isEmpty()) {
doSomethingWhenEmpty()
}
Having, Optional.ifAbsent() would be handy in these scenarios.
Currently `java.util.Optional` has ifPresent() method if we want to do something if the value is present.
Whereas if we want to do something "only" when the value is absent (empty), we are forced to use Optional.ifPresentOrElse().
In this case, we are forced to write an empty consumer / lambda (stale code) in ifPresent part like following
Optional.ifPresentOrElse(unused -> {}, doSomethingWhenEmpty());
Or use an if condition like following which is not so expressive
if (Optional.isEmpty()) {
doSomethingWhenEmpty()
}
Having, Optional.ifAbsent() would be handy in these scenarios.