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

Incorrect raw type warning for method reference

    Details

      Description

      The following produces 3 raw type warnings (with -Xlint), one for each method reference:

      import java.util.stream.Stream;
      import java.util.Optional;
      import java.util.function.Function;
      import java.util.function.Supplier;

      public class RawMethodRef {

          void test1(Stream<? extends Class<String>> stream) {
              stream.filter(Class::isInterface);
          }

          void test2(Stream<String> stream, Function<String, ? extends Optional<String>> f) {
              stream.map(f).filter(Optional::isPresent);
          }

          void test3(Stream<? extends Supplier<String>> stream) {
              stream.map(Supplier::get).filter(s -> s.isEmpty());
          }

      }

      There should be no warning, because the type argument in each case is inferred. (test3 demonstrates that, in fact, the type argument is correctly inferred and becomes the type of 's'.)

      The warning goes away if I remove the wildcards, so the problem is in the handling of capture variables.

      JDK-8039214 had the side-effect of introducing the warning in test2 -- prior to that (e.g., in JDK 8), only test1 and test3 produce warnings.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vromero Vicente Arturo Romero Zaldivar
                Reporter:
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: