Reading the JavaDoc of Optional
, I bumped in a weird method signature; I never saw in my life:
public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier)
throws X extends Throwable
At first glance, I wondered how the generic exception <X extends Throwable>
is even possible, since you can't do that (here, and here). On second thought, this starts to make sense, as it is here just to bind the Supplier
... but the supplier itself knows exactly what type it should be, before generics.
But the second line hit me:
throws X
is a complete generic exception type.
And then:
X extends Throwable
, what in the world does this mean?X
is already bound in the method signature.
- Will this by any means, solve the generic exception restriction?
- Why not just
throws Throwable
, as the rest will be erased by type erasure?
And one, not directly related question:
- Will this method be required to be caught as
catch(Throwable t)
, or by the providedSupplier
's type; since it can't be checked for at runtime?