3 ms·
what is "it doesn't work" ? The exception is part of the type, so it doesn't typecheck unless all callbacks are of type "... throws Exception"? What's the probl
by dustingetz 2y ago
what is "it doesn't work" ? The exception is part of the type, so it doesn't typecheck unless all callbacks are of type "... throws Exception"? What's the problem with that? It's not generic enough, i.e. the problem is Java generics are too weak to write something like "throws <T extends Exception>"? (Forgive me, it's been 13 years since I wrote java and only briefly, the questions are earnest)
edit, so like `@throws[T <: Exception] def effect[T](): Unit` or something, how is it supposed to work?
- lmm 2y agoYou 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!