-
Sub-task
-
Resolution: Delivered
-
P4
-
24
Lambda expressions and method references are sometimes translated as methods by the `javac` compiler. As of this release, the name of the generated methods for non-serializable lambdas and method references has been updated. Such updates might be visible when inspecting the content of a class containing non-serializable lambdas and method references using core reflection.
Moreover, the `EnclosingMethod` attribute for local and anonymous classes declared inside lambda expressions has been fixed to be compliant with JVMS 4.7.7 which states:
> In particular, method_index must be zero if the current class was immediately enclosed in source code by an instance initializer, static initializer, instance variable initializer, or class variable initializer.
This means that the following code:
```
class Outer {
Runnable action = () -> {
class Inner() { }
System.out.println(Inner.class.getEnclosingMethod());
}
public static void main(String[] args) {
new Outer().action.run();
}
}
```
will now, correctly, print `null`. That is, the local class `Inner` has no enclosing method. Earlier versions incorrectly reported the enclosing method of `Inner` to be the generated method for the lambda expression.
Moreover, the `EnclosingMethod` attribute for local and anonymous classes declared inside lambda expressions has been fixed to be compliant with JVMS 4.7.7 which states:
> In particular, method_index must be zero if the current class was immediately enclosed in source code by an instance initializer, static initializer, instance variable initializer, or class variable initializer.
This means that the following code:
```
class Outer {
Runnable action = () -> {
class Inner() { }
System.out.println(Inner.class.getEnclosingMethod());
}
public static void main(String[] args) {
new Outer().action.run();
}
}
```
will now, correctly, print `null`. That is, the local class `Inner` has no enclosing method. Earlier versions incorrectly reported the enclosing method of `Inner` to be the generated method for the lambda expression.