3 ms·
So you effectively want - class ThrowingFunction<T, R>{ public T execute() throws R; } public <T, R> higherOrderFunction(ThrowingFunction<T,R> f) throws R {
by Nursie 6y ago
So you effectively want -
class ThrowingFunction<T, R>{
public T execute() throws R;
}
public <T, R> higherOrderFunction(ThrowingFunction<T,R> f) throws R { }
Honestly I have no idea if such a construct is possible. You can write a method that throws a superclass of exceptions.
At this point though I'm going to say I also don't see the utility. By the time we're getting so abstract we're also getting into code that can be quite hard to reason about and debug.
Exceptions are first class in java AFAICT, they're just objects. You can store anything in them and pass them around freely.