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

Add a method to for performing a Consumer<T> on a non-null value

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      I have many times run into code that follows this pattern:
      if (variable.getValue() != null) {
        set("foo", variable.GetValue());
      }

      It seems like this could be simplified with a new Objects method like "whenNonNull":
      Objects.whenNonNull(variable.getValue(), (value) -> set("foo", value);

      The new Objects class method would be something like:
      static void whenNonNull (Object o, Consumer<T> consumer)

      I wasn't entirely sure where to make this enhancement request as this definitely isn't large enough to be part of a JEP.


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: