I\'ve come across a weird problem where a method reference to Thread::sleep
is ambiguous but a method with the same signature is not.
package test;
Personally I see this as some sort of recursion, somehow like this: we need to resolve the method in order to find the target type, but we need to know the target type in order to resolve the method. This has something to do with a special void compatibility rule, but I admit I do not entirely get it.
Things are even funner when you have something like this:
public static void cool(Predicate predicate) {
}
public static void cool(Function function) {
}
And try to call it via:
cool(i -> "Test"); // this will fail compilation
And btw if you make your lambda explicit, this will work:
foo((Long t) -> Thread.sleep(t), 1000L);