2 ms·
You can't be polymorphic between not throwing and throwing, or between throwing different numbers of exceptions. You have to write something like: <R> List
by lmm 2y ago
You can't be polymorphic between not throwing and throwing, or between throwing different numbers of exceptions. You have to write something like:
<R> List<R> map(Function<? super T,? extends R> mapper) { ... }
<R, E1 extends Throwable> List<R> map(FunctionThrows1<? super T,? extends R, E1> mapper) throws E1 { ... }
<R, E1 extends Throwable, E2 extends Throwable> List<R> map(FunctionThrows2<? super T,? extends R, E1, E2> mapper) throws E1, E2 { ... }
and so on until you get bored.
- catlifeonmars 2y agoAh because there is no way to express E1 | E2 as a type parameter?
- lmm 2y agoYeah. Ironically the JLS includes a complete specification of what the type E1|E2 is, because if you write a catch block that catches both then that's the type of what you catch, there's just no syntax for it.
- dustingetz 2y agoah!