Tim Mousaw wrote:. . .
. . . allowed to omit the parentheses . . . making C correct.
. . . .
It says, “allowed,” not, “required.” That should really say that parentheses may be omitted when the parameters list is reduced to one
token. In a λ like
int i ‑> i * 2, the parameters list contains one parameter, but two
tokens, and that expression will fail to compile.
Please explain more about the second question, about braces.
Campbell's JShell wrote:jshell
InFu| Welcome to JShell -- Version 21.0.1
| For an introduction type: /help intro
jshell> IntFunction x = (i) -> i * 2;
x ==> $Lambda/0x00007f13c400a200@9807454
jshell> IntFunction x = i -> i * 2;
x ==> $Lambda/0x00007f13c400a200@9807454
jshell> IntFunction x = int i -> i * 2;
| Error:
| '.class' expected
| IntFunction x = int i -> i * 2;
| ^
jshell> /exit
| Goodbye
Note the hash codes suggest that JShell recognised the two expressions as mutually equivalent.