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

Inference failure when using a constructor reference

    Details

    • Subcomponent:
    • Understanding:
      Cause Known
    • Introduced In Version:
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      javac -version
      javac 1.8.0_60


      ADDITIONAL OS VERSION INFORMATION :
      Linux desktop 4.1.6-1-ARCH #1 SMP PREEMPT Mon Aug 17 08:52:28 CEST 2015 x86_64 GNU/Linux
      Linux lab 3.13.0-63-generic #103-Ubuntu SMP Fri Aug 14 21:43:30 UTC 2015 i686 i686 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The attached code does not compile. It should. It did at least in 1.8.0_25


      REGRESSION. Last worked in version 8u40

      ADDITIONAL REGRESSION INFORMATION:
      This code compiled and worked fine in 1.8.0_25


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Error:(15, 20) java: method unmodifiableList in class java.util.Collections cannot be applied to given types;
        required: java.util.List<? extends T>
        found: java.util.Collection<Main>
        reason: cannot infer type-variable(s) E
          (actual and formal argument lists differ in length)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.ArrayList;
      import java.util.Collection;
      import java.util.Collections;
      import java.util.stream.Collectors;

      class Main {

          static Collection<Main> list = null;

          public static void main(String[] args) {
              Collections.unmodifiableList(list.stream().collect(Collectors.toCollection(ArrayList::new)));
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      import java.util.ArrayList;
      import java.util.Collection;
      import java.util.Collections;
      import java.util.stream.Collectors;

      class Main {

          static Collection<Main> list = null;

          static ArrayList create() {
              return new ArrayList();
          }

          public static void main(String[] args) {
              Collections.unmodifiableList(list.stream().collect(Collectors.toCollection(Main::create)));
          }
      }


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dlsmith Dan Smith
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: