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

15.13: Method reference expression allows array creation for void return type

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      The Java Language Specification (and javac) currently permits using an array creation expression (in the form ComponentType[]::new) as method reference expression for methods of functional interfaces with return type `void`.

      This is inconsistent with lambda expressions which explicitly require a StatementExpression (which ArrayCreationExpression is not).


      ---------- BEGIN SOURCE ----------
      // As expected: Causes compiler error
      Consumer<Integer> c = i -> new int[i];

      // Unexpected: Does not cause compiler error
      Consumer<Integer> c = int[]::new;
      ---------- END SOURCE ----------

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: