-
Bug
-
Resolution: Fixed
-
P3
-
10
-
b01
-
generic
-
generic
FULL PRODUCT VERSION :
java version "10-ea"
Java(TM) SE Runtime Environment (build 10-ea+32)
Java HotSpot(TM) 64-Bit Server VM (build 10-ea+32, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.15063]
A DESCRIPTION OF THE PROBLEM :
Type inference works for these cases:
Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).forEach(a -> System.out.println(a.i));
Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).collect(Collectors.toList()).forEach(a -> System.out.println(a.i));
But not for this one:
var list = Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).collect(Collectors.toList());
list.forEach(a -> System.out.println(a.i));
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
var list = Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).collect(Collectors.toList());
list.forEach(a -> System.out.println(a.i));
---------- END SOURCE ----------
java version "10-ea"
Java(TM) SE Runtime Environment (build 10-ea+32)
Java HotSpot(TM) 64-Bit Server VM (build 10-ea+32, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.15063]
A DESCRIPTION OF THE PROBLEM :
Type inference works for these cases:
Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).forEach(a -> System.out.println(a.i));
Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).collect(Collectors.toList()).forEach(a -> System.out.println(a.i));
But not for this one:
var list = Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).collect(Collectors.toList());
list.forEach(a -> System.out.println(a.i));
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
var list = Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).collect(Collectors.toList());
list.forEach(a -> System.out.println(a.i));
---------- END SOURCE ----------
- relates to
-
JDK-8177466 Add compiler support for local variable type-inference
- Resolved
-
JDK-8199907 JShell: NoSuchFieldError occurred due to accessing variables of intersection type inferred by `var`
- In Progress