class Bouncy<T> extends Throwable {
}
// Error: the generic class Bouncy<T> may not subclass java.lang.Throwable
Why doesn't Java support generic Throwable
s?
I realize that type erasure complicates certain things, but obviously Java gets by with a lot already, so why not push it one more notch and allow generic Throwable
s, with comprehensive compile-time check for potential problems?
I feel like the type erasure argument is rather weak. Currently, we can't do:
void process(List<String> list) {
}
void process(List<Integer> list) {
}
Of course, we get by without it. I'm not asking that we should be able to do catch Bouncy<T1>
and Bouncy<T2>
in the same try
block, but if we use them in disjoint contexts with strict compile-time enforceable rules (which is pretty much the way generics works right now), wouldn't it be workable?