Reproducer:
import java.util.function.Supplier;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
class Scratch {
public static void main(String[] args) {
Supplier<Object> x = MethodHandles.zero(Object.class)::invoke;
}
}
As MethodHandles.invoke is declared to throw Throwable, this code should not compile and fail with a 'unhandled exception Throwable'
Javac compiles that code successfully, ignoring the throws Throwable.
Tested with:
8: error: incompatible thrown types Throwable in method reference (*This is the desired result*)
11: compiles
17: compiles
19: compiles
import java.util.function.Supplier;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
class Scratch {
public static void main(String[] args) {
Supplier<Object> x = MethodHandles.zero(Object.class)::invoke;
}
}
As MethodHandles.invoke is declared to throw Throwable, this code should not compile and fail with a 'unhandled exception Throwable'
Javac compiles that code successfully, ignoring the throws Throwable.
Tested with:
8: error: incompatible thrown types Throwable in method reference (*This is the desired result*)
11: compiles
17: compiles
19: compiles