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

Add ifNotPresent to Optional

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 8u20
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE REQUEST :
      Please add the method similar to the following to java.util.Optional:

          public void ifNotPresent(Runnable cmd) {
              if (value == null)
                  cmd.run();
          }

      JUSTIFICATION :
      While refactoring my codebases to use Java 8 features, I have encountered situations where, I wanted to execute some code that handles the absent of an Optional value.


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psandoz Paul Sandoz
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: