Details
-
Bug
-
Status: Resolved
-
P4
-
Resolution: Not an Issue
-
15
-
None
-
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 ----------
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 ----------