Method signature selection for lambda expression with multiple matching target types
问题 I was answering a question and ran into a scenario I can't explain. Consider this code: interface ConsumerOne<T> { void accept(T a); } interface CustomIterable<T> extends Iterable<T> { void forEach(ConsumerOne<? super T> c); //overload } class A { private static CustomIterable<A> iterable; private static List<A> aList; public static void main(String[] args) { iterable.forEach(a -> aList.add(a)); //ambiguous iterable.forEach(aList::add); //ambiguous iterable.forEach((A a) -> aList.add(a)); /