Hacker News new | past | comments | ask | show | jobs | submit login

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.






> not adding exception sum types What's this mean?

Ideally 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 but you have to choose one base type and you can't make stdlib support it.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: