• Icon: Sub-task Sub-task
    • Resolution: Delivered
    • Icon: P4 P4
    • 9
    • 9
    • tools
    • Verified

      `javac` does not generate unchecked warnings when checking method reference return types.

      ```
      import java.util.function.*;
      import java.util.*;
       
      class Test {
         void m() {
            IntFunction<List<String>[]> sls = List[]::new; //warning
            Supplier<List<String>> sls = this::l; //warning
         }
       
         List l() { return null; }
      }
      ```
       
      Starting from <version>, `javac` will emit a warning when unchecked conversion is required for a method reference to be compatible with a functional interface target.

      This change brings the compiler in sync with JLS section 15.13.2:

      > A compile-time unchecked warning occurs if unchecked conversion was necessary for the compile-time declaration to be applicable, and this conversion would cause an unchecked warning in an invocation context.
       
      and,

      > A compile-time unchecked warning occurs if unchecked conversion was necessary for the return type R', described above, to be compatible with the function type's return type, R, and this conversion would cause an unchecked warning in an assignment context.

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: