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

compiler cannot infer type correctly when using method reference

    XMLWordPrintable

Details

    • 12
    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      The provided code not compiled, although it seems should.

      REGRESSION : Last worked in version 11.0.14

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile provided code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code to be compiled.
      ACTUAL -
      The compilation error:

      error: incompatible types: invalid method reference
                          .map(URI::create)
                               ^
          incompatible types: Object cannot be converted to String

      ---------- BEGIN SOURCE ----------
      package example;

      import java.net.URI;
      import java.net.http.HttpResponse;
      import java.util.concurrent.CompletableFuture;
      import java.util.stream.Collectors;
      import java.util.stream.Stream;

      public class Main {
          public static void main(String[] args) {
          }

          static <T> void test() {
              CompletableFuture<HttpResponse<T>> f = CompletableFuture.completedFuture(null);

              f.thenApplyAsync(response -> {
                  Stream.of("Location", "Content-Location")
                          .flatMap(s -> response.headers().allValues(s).stream())
                          .map(URI::create)
                          .collect(Collectors.toList());

                  return response;
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      To not use lambda expression instead of method reference.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: