-
Type:
Sub-task
-
Resolution: Delivered
-
Priority:
P4
-
Affects Version/s: 26
-
Component/s: tools
Prior to JDK 26, the `javac` compiler did not apply a JLS mandated capture conversion when deciding if a method reference is compatible with a given function type. This could lead the `javac` compiler to accept code like the following:
```
import java.util.function.Supplier;
class Test {
interface X<T> {
X<T> self();
}
static X<?> makeX() {return null;}
static <R> X<R> create(Supplier<? extends R> supplier) {return null;}
static X<X<?>> methodRef() {
return create(Test::makeX).self();
}
}
```
Starting from JDK 26, the `javac` compiler will apply the JLS mandated capture conversion when deciding if a method reference is compatible with a given function type. Code, like that in the sample above, will be rejected.
```
import java.util.function.Supplier;
class Test {
interface X<T> {
X<T> self();
}
static X<?> makeX() {return null;}
static <R> X<R> create(Supplier<? extends R> supplier) {return null;}
static X<X<?>> methodRef() {
return create(Test::makeX).self();
}
}
```
Starting from JDK 26, the `javac` compiler will apply the JLS mandated capture conversion when deciding if a method reference is compatible with a given function type. Code, like that in the sample above, will be rejected.