4 ms·
Yeah, Java botched generics by not adding exception sum types. stream.map(f).collect(…) should throw whatever f can throw, but instead f has to wrap any checked
by erik_seaberg 7y ago
Yeah, Java botched generics by not adding exception sum types. stream.map(f).collect(…) should throw whatever f can throw, but instead f has to wrap any checked exception, which makes them nearly unusable in practice.
But the drudgery of explicitly passing every error up the stack over and over is not a good use of human beings' time. We can generate that if we must, but not actually read it.
- therealdrag0 7y ago> not adding exception sum types What's this mean?
- erik_seaberg 7y agoIdeally we want something like class Stream<T> { <R, X> Stream<R> map( Function<? super T, ? extends R, throws X> mapper ) throws X } and if you pass a function that throws, say, IOException and SQLException, then X=IOException|SQLException and that's what that call to #map throws. You can sort of do it by http://natpryce.com/articles/000738.html http://natpryce.com/articles/000738.html but you have to choose one base type and you can't make stdlib support it.