Method reference doesn't work correctly

Srikanth srikanth.adayapalam at oracle.com
Thu May 7 09:27:02 UTC 2020



On 07/05/20 3:55 am, Remi Forax wrote:
> Hi all,
> the inference of method reference doesn't work properly
>
>    @__inline__ static class Foo {
>      int x;
>      Foo(int x) { this.x = x; }
>    }
>
>    static void m(Foo foo) {
>      System.out.println("inline");
>    }
>    static void m(Foo.ref foo) {
>      System.out.println("ref");
>    }

There is something wrong with the braces - these m() methods are not 
inside the class Foo,
but the method reference below is to Foo::m

Srikanth

>    public static void main(String[] args) {
>      var list = List.of(new Foo(3));
>      list.forEach(e -> m(e));
>      list.forEach(Foo::m);
>    }
>
>
> Hello.java:19: error: invalid method reference
>      list.forEach(Foo::m);
>                   ^
>    cannot find symbol
>      symbol:   method m(T)
>      location: class Foo
>    where T is a type-variable:
>      T extends Object declared in interface Iterable
>
> regards,
> Rémi



More information about the amber-dev mailing list