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

static/instance overload leads to 'unexpected static method found in unbound lookup' when resolving method reference

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 16
    • 11, 14
    • tools
    • b33

        Minimized test case:

        import java.util.function.*;
         
        public class Test {
            public String foo(Object o) { return "foo"; }
            public static String foo(String o) { return "bar"; }

            public void test() {
                Function<String, String> f = Test::foo;
            }
        }

        $ javac -version
        javac 1.8.0_212
        $ javac Test.java
        <OK>

        $ ~/trunks/jdk-jdk/build/linux-x86_64-server-release/images/jdk/bin/javac -version
        javac 14-internal
        $ ~/trunks/jdk-jdk/build/linux-x86_64-server-release/images/jdk/bin/javac Test.java
        Test.java:8: error: incompatible types: invalid method reference
             Function<String, String> f = Test::foo;
             ^
            unexpected static method foo(String) found in unbound lookup
        1 error

        So it works on 8, and fails on 11, 14.

              vromero Vicente Arturo Romero Zaldivar
              shade Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: