suspicious ambiguous method error (b.103)
Dan Smith
daniel.smith at oracle.com
Tue Aug 27 10:38:41 PDT 2013
Looks like the error is correct, but the message needs to be improved.
The way it works is that every method reference of the form Foo::bar can be interpreted in two ways:
(args) -> Foo.bar(args) (static method reference)
(Foo receiver, args) -> receiver.bar(args) (unbound instance method reference)
So, for MyTest::yyy, there are two interpretations (where the functional interface target is Comparator<MyTest>, i.e. (MyTest, MyTest)->int):
(MyTest a1, MyTest a2) -> MyTest.yyy(c1, c2)
(MyTest receiver, MyTest a1) -> r.yyy(c1)
Since the method invocation searches for both forms succeed (the first one ultimately doesn't make sense because 'yyy' isn't static, but method searches, by design, don't distinguish between static and non-static declarations), there's an ambiguity.
—Dan
On Aug 26, 2013, at 7:55 AM, Anna Kozlova <Anna.Kozlova at jetbrains.com> wrote:
> Hi guys,
>
>
>
> I've got an error
>
>
>
> java: incompatible types: invalid method reference
>
> reference to yyy is ambiguous
>
> both method yyy(MyTest...) in MyTest and method yyy(MyTest...) in
> MyTest match
>
>
>
> for code
>
>
>
> import java.util.Comparator;
>
> class MyTest {
>
> void test() {
>
> Comparator<MyTest> c = MyTest::yyy;
>
> }
>
> int yyy(MyTest... p) { return 1; }
>
> }
>
>
>
> Thank you
> Anna Kozlova
> JetBrains Inc.
> <http://www.intellij.com/> http://www.jetbrains.com
> "Develop with pleasure!"
>
>
>
>
More information about the lambda-dev
mailing list