-
Enhancement
-
Resolution: Fixed
-
P3
-
None
-
b11
There is an Optional.isPresent method; it would be helpful to have its inverse as well. It should probably be named isEmpty, since the static factory method for getting an empty optional is Optional.empty.
See the discussion here:
http://mail.openjdk.java.net/pipermail/core-libs-dev/2017-April/047274.html
Generally we avoid adding methods that are simple inverses of each other. For example, there is String.isEmpty but no String.nonEmpty, and there is Collection.isEmpty but no Collection.nonEmpty. For these objects, it's perfectly reasonable to operate on an empty String (e.g., searching or appending it) or collection (e.g., iterating over it) so I'd argue that for these objects and many others, emptiness/non-emptiness isn't fundamental.
However, with references, null/non-null is pretty fundamental, we have Objects.isNull and Objects.nonNull. Similarly with Optional, the empty/present dichotomy is quite fundamental, so there should be isEmpty alongside of isPresent.
There should be corresponding isEmpty() methods added to OptionalDouble, OptionalInt, and OptionalLong.
See the discussion here:
http://mail.openjdk.java.net/pipermail/core-libs-dev/2017-April/047274.html
Generally we avoid adding methods that are simple inverses of each other. For example, there is String.isEmpty but no String.nonEmpty, and there is Collection.isEmpty but no Collection.nonEmpty. For these objects, it's perfectly reasonable to operate on an empty String (e.g., searching or appending it) or collection (e.g., iterating over it) so I'd argue that for these objects and many others, emptiness/non-emptiness isn't fundamental.
However, with references, null/non-null is pretty fundamental, we have Objects.isNull and Objects.nonNull. Similarly with Optional, the empty/present dichotomy is quite fundamental, so there should be isEmpty alongside of isPresent.
There should be corresponding isEmpty() methods added to OptionalDouble, OptionalInt, and OptionalLong.
- csr for
-
JDK-8201606 (opt) add Optional.isEmpty
-
- Closed
-