All Downloads are FREE. Search and download functionalities are using the official Maven repository.

errorprone.bugpattern.AmbiguousMethodReference.md Maven / Gradle / Ivy

The newest version!
The following code is fine in Java 7, but poses a problem in Java 8.

```java
static class A {
  B c(D d) { return null; }
  static B c(A a, D d) { return null; }
}
```

The method reference `A::c` of the instance method `c` has an implicit first
parameter for the `this` pointer. So both methods that `A::c` could resolve to
are compatible with `BiFunction`, and the method reference is
ambiguous.

```java
void f(BiFunction f) { ... }
```

```
error: incompatible types: invalid method reference
    f(A::c);
      ^
    reference to c is ambiguous
      both method c(A,D) in A and method c(D) in A match
```

Consider renaming one of the methods to avoid the ambiguity.




© 2015 - 2025 Weber Informatics LLC | Privacy Policy