I have this class called Container:
public class Container {
private final Map map = new HashMap<>();
publ
According to the JLS §15.12.2.2:
An argument expression is considered pertinent to applicability for a potentially applicable method
munless it has one of the following forms:
- An implicitly typed lambda expression1.
- An inexact method reference expression2.
- [...]
Therefore:
verify("bar", tokens.get("foo", e -> String.valueOf(e)));
an implicitly typed lambda expression e -> String.valueOf(e) is skipped from the applicability check during overload resolution - both verify(...) methods become applicable - hence the ambiguity.
In comparison, here are some examples that will work, because the types are specified explicitly:
verify("bar", tokens.get("foo", (Function
1 - An implicitly typed lambda expression is a lambda expression, where the types of all its formal parameters are inferred.
2 - An inexact method reference - one with multiple overloads.