3 ms·
I'd say it is due to a lack of variadic type parameters. You can write something like this: <T, X extends Throwable> void forEach(ThrowingConsumer<T, X> f)
by PhilipRoman 3y ago
I'd say it is due to a lack of variadic type parameters. You can write something like this:
<T, X extends Throwable> void forEach(ThrowingConsumer<T, X> f) throws X;
But the only way to have multiple exception types without losing static type checking is to have multiple X parameters, like X1, X2, X3... (with unused parameters being set to some subtype of RuntimeException so that they do not participate in checked exception handling).
Whether or not it is worth to write this madness just to satisfy one's OCD is up to the reader.
- ackfoobar 3y ago> it is due to a lack of variadic type parameters To be pedantic, it is due to union types "not complemented anywhere else in Java's type system". Adding variadic type params is a way to solve this. Another way is, of course, to support union types. > with unused parameters being set to some subtype of RuntimeException Or the `Nothing` type (`never` in TypeScript), where `A | Nothing = A`.