-
Bug
-
Resolution: Fixed
-
P3
-
17, 21, 22
-
Observed in 17, 21 and 22 build 22-ea+27-2262.
-
b05
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8324379 | 22.0.1 | Jan Lahoda | P3 | Resolved | Fixed | b02 |
JDK-8323656 | 22 | Jan Lahoda | P3 | Resolved | Fixed | b32 |
A list of records that implement a common Shape interface is inferred as a List<Record &Shape>.
When its elements are passed to a Consumer<Shape> in JShell, the following error is displayed:
Error:
| incompatible types: java.util.function.Consumer<Shape> cannot be converted to java.util.function.Consumer<? super java.lang.Record>
This error is not there in a classical main method.
The following code shows this bug.
```
interface Shape {}
record Square(int edge) implements Shape {}
record Circle(int radius) implements Shape {}
Consumer<Shape> printShape = System.out::println;
Square square = new Square(1);
Circle circle = new Circle(1);
var shapes = List.of(square, circle);
shapes.forEach(printShape);
```
When its elements are passed to a Consumer<Shape> in JShell, the following error is displayed:
Error:
| incompatible types: java.util.function.Consumer<Shape> cannot be converted to java.util.function.Consumer<? super java.lang.Record>
This error is not there in a classical main method.
The following code shows this bug.
```
interface Shape {}
record Square(int edge) implements Shape {}
record Circle(int radius) implements Shape {}
Consumer<Shape> printShape = System.out::println;
Square square = new Square(1);
Circle circle = new Circle(1);
var shapes = List.of(square, circle);
shapes.forEach(printShape);
```
- backported by
-
JDK-8323656 JShell - Incorrect type inference in lists of records implementing interfaces
-
- Resolved
-
-
JDK-8324379 JShell - Incorrect type inference in lists of records implementing interfaces
-
- Resolved
-
- links to
-
Commit openjdk/jdk22/07a8911c
-
Commit openjdk/jdk/57a65fe4
-
Review openjdk/jdk22/40
-
Review openjdk/jdk/17223
(1 links to)