Details

    • Type: Enhancement
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      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.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            smarks Stuart Marks
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: