Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8191842

JShell: Inferred type information is lost when assigning types to a "var"

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b01
    • CPU:
      generic
    • OS:
      generic

      Description

      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 ----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jlahoda Jan Lahoda
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: