Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8228615

Optional.empty() doc should suggest isEmpty() instead of isPresent()

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      The documentation of java.util.Optional.empty() says:
      >Though it may be tempting to do so, avoid testing if an object is empty by comparing with == against instances returned by Optional.empty(). There is no guarantee that it is a singleton. Instead, use isPresent().

      This dates back to when there was no `isEmpty()`, however in Java 11 this method was added (JDK-8184693). Therefore the documentation for `empty()` should refer only, or additionally, to `isEmpty()`:
      >Though it may be tempting to do so, avoid testing if an object is empty by comparing with == against instances returned by Optional.empty(). There is no guarantee that it is a singleton. Instead, use isEmpty().

      Same for OptionalInt, OptionalDouble and OptionalLong.


        Attachments

          Activity

            People

            • Assignee:
              smarks Stuart Marks
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: