Details
-
Bug
-
Resolution: Fixed
-
P4
-
None
-
b24
Description
Spec (https://cr.openjdk.org/~abimpoudis/unnamed/jep443-20230322/specs/unnamed-jls.html#jls-6.1) says:
If a declaration does not include an identifier, but instead includes a mask (_, underscore), then the entity cannot be referred to by name. The following kinds of entity may be declared using a mask:
A formal parameter of a lambda expression (15.27.1)
There is no assertion expecting a compiler-time error when there are mixed masked and unmasked variables in lambda parameter list.
Compiler, however, throws an error:
interface Foo {
int foo(int a, int b);
}
…
Foo o = (int _, int b) -> { return 1;}; //error here
invalid lambda parameter declaration
(cannot mix implicitly-typed and explicitly-typed parameters)
java --version
java 21-internal 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21-internal-LTS-2023-05-05-1610040.angelos.bimpoudis.dev)
Java HotSpot(TM) 64-Bit Server VM (build 21-internal-LTS-2023-05-05-1610040.angelos.bimpoudis.dev, mixed mode, sharing)
If a declaration does not include an identifier, but instead includes a mask (_, underscore), then the entity cannot be referred to by name. The following kinds of entity may be declared using a mask:
A formal parameter of a lambda expression (15.27.1)
There is no assertion expecting a compiler-time error when there are mixed masked and unmasked variables in lambda parameter list.
Compiler, however, throws an error:
interface Foo {
int foo(int a, int b);
}
…
Foo o = (int _, int b) -> { return 1;}; //error here
invalid lambda parameter declaration
(cannot mix implicitly-typed and explicitly-typed parameters)
java --version
java 21-internal 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21-internal-LTS-2023-05-05-1610040.angelos.bimpoudis.dev)
Java HotSpot(TM) 64-Bit Server VM (build 21-internal-LTS-2023-05-05-1610040.angelos.bimpoudis.dev, mixed mode, sharing)