Method reference doesn't work correctly

Remi Forax forax at univ-mlv.fr
Wed May 6 22:25:39 UTC 2020


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");
  }

  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