Method reference doesn't work correctly

Remi Forax forax at univ-mlv.fr
Thu May 7 16:19:17 UTC 2020


[move to valhalla-dev]

----- Mail original -----
> De: "Srikanth" <srikanth.adayapalam at oracle.com>
> À: "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Jeudi 7 Mai 2020 11:27:02
> Objet: Re: Method reference doesn't work correctly

> 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


I was trying to create a reproducer for what you have called problem 3 in [1],
but i goof so no need to create a bug for this one.

> 
> Srikanth

Rémi

[1] https://github.com/openjdk/valhalla/pull/32

> 
>>    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 valhalla-dev mailing list