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

Add ifNotPresent to Optional

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 8u20
    • core-libs
    • generic
    • generic

      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.


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

              Created:
              Updated:
              Resolved: