Bear with me, the introduction is a bit long-winded but this is an interesting puzzle.
I have this code:
public class Testcase {
public static void m
First, according to §15.27.2 the expression:
() -> { throw ... }
Is both void-compatible, and value-compatible, so it's compatible (§15.27.3) with Supplier:
class Test {
void foo(Supplier> bar) {
throw new RuntimeException();
}
void qux() {
foo(() -> { throw new IllegalArgumentException(); });
}
}
(see that it compiles)
Second, according to §15.12.2.5 Supplier (where T is a reference type) is more specific than Runnable:
Let:
SupplierRunnable() -> { throw ... }So that:
T get() ==> Rs := Tvoid run() ==> Rt := voidAnd:
S is not a superinterface or a subinterface of Tvoid