My recently posted question, "Optional.isEmpty() Coming to Java?," was prompted by a core-libs-dev mailing list post titled "RFR: 8184693: (opt) add Optional.isEmpty." The current JDK 11 early-access builds (such as the OpenJDK JDK Early Access Build 23 that I use in this post) now include the
isEmpty() method on certain Optional classes, including Optional, OptionalDouble, OptionalInt, and OptionalLong. This allows for more fluent expression in cases that formerly relied upon negation of Optional.isPresent() — or !OptionalDouble.isPresent(), !OptionalInt.isPresent(), or !OptionalLong.ifPresent() — as was done previously.
The next simple and contrived code listing demonstrates the